Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: chrome/browser/cocoa/applescript/window_applescript_test.mm

Issue 3046042: Added AppleScript support (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/cocoa/applescript/window_applescript.mm ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 "base/scoped_nsobject.h"
6 #include "base/sys_string_conversions.h"
7 #import "chrome/browser/app_controller_mac.h"
8 #import "chrome/browser/chrome_browser_application_mac.h"
9 #import "chrome/browser/cocoa/applescript/constants_applescript.h"
10 #import "chrome/browser/cocoa/applescript/error_applescript.h"
11 #import "chrome/browser/cocoa/applescript/tab_applescript.h"
12 #import "chrome/browser/cocoa/applescript/window_applescript.h"
13 #include "chrome/browser/profile.h"
14 #include "chrome/test/in_process_browser_test.h"
15 #include "googleurl/src/gurl.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #import "testing/gtest_mac.h"
18
19 typedef InProcessBrowserTest WindowAppleScriptTest;
20
21 // Create a window in default/normal mode.
22 IN_PROC_BROWSER_TEST_F(WindowAppleScriptTest, DefaultCreation) {
23 scoped_nsobject<WindowAppleScript> aWindow(
24 [[WindowAppleScript alloc] init]);
25 EXPECT_TRUE(aWindow.get());
26 NSString* mode = [aWindow.get() mode];
27 EXPECT_NSEQ(AppleScript::kNormalWindowMode,
28 mode);
29 }
30
31 // Create a window with a |NULL profile|.
32 IN_PROC_BROWSER_TEST_F(WindowAppleScriptTest, CreationWithNoProfile) {
33 scoped_nsobject<WindowAppleScript> aWindow(
34 [[WindowAppleScript alloc] initWithProfile:NULL]);
35 EXPECT_FALSE(aWindow.get());
36 }
37
38 // Create a window with a particular profile.
39 IN_PROC_BROWSER_TEST_F(WindowAppleScriptTest, CreationWithProfile) {
40 Profile* defaultProfile = [[NSApp delegate] defaultProfile];
41 scoped_nsobject<WindowAppleScript> aWindow(
42 [[WindowAppleScript alloc] initWithProfile:defaultProfile]);
43 EXPECT_TRUE(aWindow.get());
44 EXPECT_TRUE([aWindow.get() uniqueID]);
45 EXPECT_EQ([aWindow.get() container],
46 [BrowserCrApplication sharedApplication]);
47 EXPECT_NSEQ(AppleScript::kWindowsProperty,
48 [aWindow.get() containerProperty]);
49 }
50
51 // Create a window with no |Browser*|.
52 IN_PROC_BROWSER_TEST_F(WindowAppleScriptTest, CreationWithNoBrowser) {
53 scoped_nsobject<WindowAppleScript> aWindow(
54 [[WindowAppleScript alloc] initWithBrowser:NULL]);
55 EXPECT_FALSE(aWindow.get());
56 }
57
58 // Create a window with |Browser*| already present.
59 IN_PROC_BROWSER_TEST_F(WindowAppleScriptTest, CreationWithBrowser) {
60 scoped_nsobject<WindowAppleScript> aWindow(
61 [[WindowAppleScript alloc] initWithBrowser:browser()]);
62 EXPECT_TRUE(aWindow.get());
63 EXPECT_TRUE([aWindow.get() uniqueID]);
64 EXPECT_EQ([aWindow.get() container],
65 [BrowserCrApplication sharedApplication]);
66 EXPECT_NSEQ(AppleScript::kWindowsProperty,
67 [aWindow.get() containerProperty]);
68 }
69
70 // Tabs within the window.
71 IN_PROC_BROWSER_TEST_F(WindowAppleScriptTest, Tabs) {
72 scoped_nsobject<WindowAppleScript> aWindow(
73 [[WindowAppleScript alloc] initWithBrowser:browser()]);
74 NSArray* tabs = [aWindow.get() tabs];
75 EXPECT_EQ(1U, [tabs count]);
76 TabAppleScript* tab1 = [tabs objectAtIndex:0];
77 EXPECT_EQ([tab1 container], aWindow.get());
78 EXPECT_NSEQ(AppleScript::kTabsProperty,
79 [tab1 containerProperty]);
80 }
81
82 // Insert a new tab.
83 IN_PROC_BROWSER_TEST_F(WindowAppleScriptTest, InsertTab) {
84 // Emulate what applescript would do when creating a new tab.
85 scoped_nsobject<TabAppleScript> aTab([[TabAppleScript alloc] init]);
86 [aTab.get() setURL:@"http://google.com"];
87 scoped_nsobject<WindowAppleScript> aWindow(
88 [[WindowAppleScript alloc] initWithBrowser:browser()]);
89 [aWindow.get() insertInTabs:aTab.get()];
90 EXPECT_EQ([aTab.get() container], aWindow.get());
91 EXPECT_NSEQ(AppleScript::kTabsProperty,
92 [aTab.get() containerProperty]);
93 TabAppleScript* tab2 = [[aWindow.get() tabs] objectAtIndex:1];
94 EXPECT_EQ(GURL("http://google.com"),
95 GURL(base::SysNSStringToUTF8([tab2 URL])));
96 }
97
98 // Insert a new tab at a particular position
99 IN_PROC_BROWSER_TEST_F(WindowAppleScriptTest, InsertTabAtPosition) {
100 scoped_nsobject<TabAppleScript> tab1([[TabAppleScript alloc] init]);
101 scoped_nsobject<TabAppleScript> tab2([[TabAppleScript alloc] init]);
102 scoped_nsobject<WindowAppleScript> aWindow(
103 [[WindowAppleScript alloc] initWithBrowser:browser()]);
104 [aWindow.get() insertInTabs:tab1.get()];
105 [aWindow.get() insertInTabs:tab2.get()];
106
107 scoped_nsobject<TabAppleScript> aTab([[TabAppleScript alloc] init]);
108 [aWindow.get() insertInTabs:aTab.get() atIndex:1];
109 TabAppleScript* tab = [[aWindow.get() tabs] objectAtIndex:1];
110 EXPECT_NSEQ([aTab.get() uniqueID],
111 [tab uniqueID]);
112 }
113
114 // Inserting and deleting tabs.
115 IN_PROC_BROWSER_TEST_F(WindowAppleScriptTest, InsertAndDeleteTabs) {
116 scoped_nsobject<WindowAppleScript> aWindow(
117 [[WindowAppleScript alloc] initWithBrowser:browser()]);
118 scoped_nsobject<TabAppleScript> aTab;
119 int count;
120 for (int i = 0; i < 5; ++i) {
121 for (int j = 0; j < 3; ++j) {
122 aTab.reset([[TabAppleScript alloc] init]);
123 [aWindow.get() insertInTabs:aTab.get()];
124 }
125 count = 3 * i + 4;
126 EXPECT_EQ((int)[[aWindow.get() tabs] count], count);
127 }
128
129 count = (int)[[aWindow.get() tabs] count];
130 for (int i = 0; i < 5; ++i) {
131 for(int j = 0; j < 3; ++j) {
132 [aWindow.get() removeFromTabsAtIndex:0];
133 }
134 count = count - 3;
135 EXPECT_EQ((int)[[aWindow.get() tabs] count], count);
136 }
137 }
138
139 // Getting and setting values from the NSWindow.
140 IN_PROC_BROWSER_TEST_F(WindowAppleScriptTest, NSWindowTest) {
141 scoped_nsobject<WindowAppleScript> aWindow(
142 [[WindowAppleScript alloc] initWithBrowser:browser()]);
143 [aWindow.get() setValue:[NSNumber numberWithBool:YES]
144 forKey:@"isMiniaturized"];
145 EXPECT_TRUE([[aWindow.get() valueForKey:@"isMiniaturized"] boolValue]);
146 [aWindow.get() setValue:[NSNumber numberWithBool:NO]
147 forKey:@"isMiniaturized"];
148 EXPECT_FALSE([[aWindow.get() valueForKey:@"isMiniaturized"] boolValue]);
149 }
150
151 // Getting and setting the active tab.
152 IN_PROC_BROWSER_TEST_F(WindowAppleScriptTest, ActiveTab) {
153 scoped_nsobject<WindowAppleScript> aWindow(
154 [[WindowAppleScript alloc] initWithBrowser:browser()]);
155 scoped_nsobject<TabAppleScript> aTab([[TabAppleScript alloc] init]);
156 [aWindow.get() insertInTabs:aTab.get()];
157 [aWindow.get() setActiveTabIndex:[NSNumber numberWithInt:2]];
158 EXPECT_EQ(2, [[aWindow.get() activeTabIndex] intValue]);
159 TabAppleScript* tab2 = [[aWindow.get() tabs] objectAtIndex:1];
160 EXPECT_NSEQ([[aWindow.get() activeTab] uniqueID],
161 [tab2 uniqueID]);
162 }
163
164 // Order of windows.
165 IN_PROC_BROWSER_TEST_F(WindowAppleScriptTest, WindowOrder) {
166 scoped_nsobject<WindowAppleScript> window2(
167 [[WindowAppleScript alloc] initWithBrowser:browser()]);
168 scoped_nsobject<WindowAppleScript> window1(
169 [[WindowAppleScript alloc] init]);
170 EXPECT_EQ([window1.get() windowComparator:window2.get()], NSOrderedAscending);
171 EXPECT_EQ([window2.get() windowComparator:window1.get()],
172 NSOrderedDescending);
173 }
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/applescript/window_applescript.mm ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698