browsercrapplication+applescript_test.mm revision 5821806d5e7f356e8fa4b058a389a808ea183019
1// Copyright (c) 2011 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#import <Cocoa/Cocoa.h> 6 7#include "chrome/browser/profiles/profile.h" 8#include "chrome/browser/ui/browser.h" 9#include "chrome/browser/ui/browser_tabstrip.h" 10#import "chrome/browser/ui/cocoa/applescript/browsercrapplication+applescript.h" 11#import "chrome/browser/ui/cocoa/applescript/constants_applescript.h" 12#import "chrome/browser/ui/cocoa/applescript/window_applescript.h" 13#include "chrome/test/base/in_process_browser_test.h" 14#include "testing/gtest/include/gtest/gtest.h" 15#include "testing/gtest_mac.h" 16#include "ui/gfx/size.h" 17 18typedef InProcessBrowserTest BrowserCrApplicationAppleScriptTest; 19 20// Create windows of different |Type|. 21IN_PROC_BROWSER_TEST_F(BrowserCrApplicationAppleScriptTest, Creation) { 22 // Create additional |Browser*| objects of different type. 23 Profile* profile = browser()->profile(); 24 Browser* b1 = 25 new Browser(Browser::CreateParams(Browser::TYPE_POPUP, profile)); 26 Browser* b2 = new Browser( 27 Browser::CreateParams::CreateForApp( 28 Browser::TYPE_PANEL, "Test", gfx::Rect(), profile)); 29 30 EXPECT_EQ(3U, [[NSApp appleScriptWindows] count]); 31 for (WindowAppleScript* window in [NSApp appleScriptWindows]) { 32 EXPECT_NSEQ(AppleScript::kWindowsProperty, 33 [window containerProperty]); 34 EXPECT_NSEQ(NSApp, [window container]); 35 } 36 37 // Close the additional browsers. 38 chrome::CloseAllTabs(b1); 39 chrome::CloseAllTabs(b2); 40} 41 42// Insert a new window. 43IN_PROC_BROWSER_TEST_F(BrowserCrApplicationAppleScriptTest, InsertWindow) { 44 // Emulate what applescript would do when creating a new window. 45 // Emulate a script like |set var to make new window with properties 46 // {visible:false}|. 47 scoped_nsobject<WindowAppleScript> aWindow([[WindowAppleScript alloc] init]); 48 scoped_nsobject<NSNumber> var([[aWindow.get() uniqueID] copy]); 49 [aWindow.get() setValue:[NSNumber numberWithBool:YES] forKey:@"isVisible"]; 50 51 [NSApp insertInAppleScriptWindows:aWindow.get()]; 52 53 // Represents the window after it is added. 54 WindowAppleScript* window = [[NSApp appleScriptWindows] objectAtIndex:0]; 55 EXPECT_NSEQ([NSNumber numberWithBool:YES], 56 [aWindow.get() valueForKey:@"isVisible"]); 57 EXPECT_EQ([window container], NSApp); 58 EXPECT_NSEQ(AppleScript::kWindowsProperty, 59 [window containerProperty]); 60 EXPECT_NSEQ(var, [window uniqueID]); 61} 62 63// Inserting and deleting windows. 64IN_PROC_BROWSER_TEST_F(BrowserCrApplicationAppleScriptTest, 65 InsertAndDeleteWindows) { 66 scoped_nsobject<WindowAppleScript> aWindow; 67 int count; 68 // Create a bunch of windows. 69 for (int i = 0; i < 5; ++i) { 70 for (int j = 0; j < 3; ++j) { 71 aWindow.reset([[WindowAppleScript alloc] init]); 72 [NSApp insertInAppleScriptWindows:aWindow.get()]; 73 } 74 count = 3 * i + 4; 75 EXPECT_EQ(count, (int)[[NSApp appleScriptWindows] count]); 76 } 77 78 // Remove all the windows, just created. 79 count = (int)[[NSApp appleScriptWindows] count]; 80 for (int i = 0; i < 5; ++i) { 81 for(int j = 0; j < 3; ++j) { 82 [NSApp removeFromAppleScriptWindowsAtIndex:0]; 83 } 84 count = count - 3; 85 EXPECT_EQ(count, (int)[[NSApp appleScriptWindows] count]); 86 } 87} 88 89// Check for objectSpecifer of the root scripting object. 90IN_PROC_BROWSER_TEST_F(BrowserCrApplicationAppleScriptTest, ObjectSpecifier) { 91 // Should always return nil to indicate its the root scripting object. 92 EXPECT_EQ(nil, [NSApp objectSpecifier]); 93} 94 95// Bookmark folders at the root level. 96// http://code.google.com/p/chromium/issues/detail?id=84299 97IN_PROC_BROWSER_TEST_F(BrowserCrApplicationAppleScriptTest, 98 DISABLED_BookmarkFolders) { 99 NSArray* bookmarkFolders = [NSApp bookmarkFolders]; 100 EXPECT_EQ(2U, [bookmarkFolders count]); 101 102 for (BookmarkFolderAppleScript* bookmarkFolder in bookmarkFolders) { 103 EXPECT_EQ(NSApp, 104 [bookmarkFolder container]); 105 EXPECT_NSEQ(AppleScript::kBookmarkFoldersProperty, 106 [bookmarkFolder containerProperty]); 107 } 108 109 EXPECT_NSEQ(@"Other Bookmarks", [[NSApp otherBookmarks] title]); 110 EXPECT_NSEQ(@"Bookmarks Bar", [[NSApp bookmarksBar] title]); 111} 112