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

Side by Side Diff: chrome/browser/extensions/api/tabs/tabs_test.cc

Issue 10694106: Added support for multiple parameters to Extension API callbacks. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Synced. Created 8 years, 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/tabs/tabs.h" 5 #include "chrome/browser/extensions/api/tabs/tabs.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 keys::kWindowNotFoundError)); 44 keys::kWindowNotFoundError));
45 45
46 // Basic window details. 46 // Basic window details.
47 gfx::Rect bounds; 47 gfx::Rect bounds;
48 if (browser()->window()->IsMinimized()) 48 if (browser()->window()->IsMinimized())
49 bounds = browser()->window()->GetRestoredBounds(); 49 bounds = browser()->window()->GetRestoredBounds();
50 else 50 else
51 bounds = browser()->window()->GetBounds(); 51 bounds = browser()->window()->GetBounds();
52 52
53 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 53 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary(
54 utils::RunFunctionAndReturnResult( 54 utils::RunFunctionAndReturnSingleResult(
55 new GetWindowFunction(), 55 new GetWindowFunction(),
56 base::StringPrintf("[%u]", window_id), 56 base::StringPrintf("[%u]", window_id),
57 browser()))); 57 browser())));
58 EXPECT_EQ(window_id, utils::GetInteger(result.get(), "id")); 58 EXPECT_EQ(window_id, utils::GetInteger(result.get(), "id"));
59 EXPECT_FALSE(utils::GetBoolean(result.get(), "incognito")); 59 EXPECT_FALSE(utils::GetBoolean(result.get(), "incognito"));
60 EXPECT_EQ("normal", utils::GetString(result.get(), "type")); 60 EXPECT_EQ("normal", utils::GetString(result.get(), "type"));
61 EXPECT_EQ(bounds.x(), utils::GetInteger(result.get(), "left")); 61 EXPECT_EQ(bounds.x(), utils::GetInteger(result.get(), "left"));
62 EXPECT_EQ(bounds.y(), utils::GetInteger(result.get(), "top")); 62 EXPECT_EQ(bounds.y(), utils::GetInteger(result.get(), "top"));
63 EXPECT_EQ(bounds.width(), utils::GetInteger(result.get(), "width")); 63 EXPECT_EQ(bounds.width(), utils::GetInteger(result.get(), "width"));
64 EXPECT_EQ(bounds.height(), utils::GetInteger(result.get(), "height")); 64 EXPECT_EQ(bounds.height(), utils::GetInteger(result.get(), "height"));
65 65
66 // With "populate" enabled. 66 // With "populate" enabled.
67 result.reset(utils::ToDictionary( 67 result.reset(utils::ToDictionary(
68 utils::RunFunctionAndReturnResult( 68 utils::RunFunctionAndReturnSingleResult(
69 new GetWindowFunction(), 69 new GetWindowFunction(),
70 base::StringPrintf("[%u, {\"populate\": true}]", window_id), 70 base::StringPrintf("[%u, {\"populate\": true}]", window_id),
71 browser()))); 71 browser())));
72 72
73 EXPECT_EQ(window_id, utils::GetInteger(result.get(), "id")); 73 EXPECT_EQ(window_id, utils::GetInteger(result.get(), "id"));
74 // "populate" was enabled so tabs should be populated. 74 // "populate" was enabled so tabs should be populated.
75 ListValue* tabs = NULL; 75 ListValue* tabs = NULL;
76 EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs)); 76 EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs));
77 77
78 // TODO(aa): Can't assume window is focused. On mac, calling Activate() from a 78 // TODO(aa): Can't assume window is focused. On mac, calling Activate() from a
79 // browser test doesn't seem to do anything, so can't test the opposite 79 // browser test doesn't seem to do anything, so can't test the opposite
80 // either. 80 // either.
81 EXPECT_EQ(browser()->window()->IsActive(), 81 EXPECT_EQ(browser()->window()->IsActive(),
82 utils::GetBoolean(result.get(), "focused")); 82 utils::GetBoolean(result.get(), "focused"));
83 83
84 // TODO(aa): Minimized and maximized dimensions. Is there a way to set 84 // TODO(aa): Minimized and maximized dimensions. Is there a way to set
85 // minimize/maximize programmatically? 85 // minimize/maximize programmatically?
86 86
87 // Popup. 87 // Popup.
88 Browser* popup_browser = Browser::CreateWithParams( 88 Browser* popup_browser = Browser::CreateWithParams(
89 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile())); 89 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile()));
90 result.reset(utils::ToDictionary( 90 result.reset(utils::ToDictionary(
91 utils::RunFunctionAndReturnResult( 91 utils::RunFunctionAndReturnSingleResult(
92 new GetWindowFunction(), 92 new GetWindowFunction(),
93 base::StringPrintf( 93 base::StringPrintf(
94 "[%u]", ExtensionTabUtil::GetWindowId(popup_browser)), 94 "[%u]", ExtensionTabUtil::GetWindowId(popup_browser)),
95 browser()))); 95 browser())));
96 EXPECT_EQ("popup", utils::GetString(result.get(), "type")); 96 EXPECT_EQ("popup", utils::GetString(result.get(), "type"));
97 97
98 // Panel. 98 // Panel.
99 Browser* panel_browser = Browser::CreateWithParams( 99 Browser* panel_browser = Browser::CreateWithParams(
100 Browser::CreateParams(Browser::TYPE_PANEL, browser()->profile())); 100 Browser::CreateParams(Browser::TYPE_PANEL, browser()->profile()));
101 result.reset(utils::ToDictionary( 101 result.reset(utils::ToDictionary(
102 utils::RunFunctionAndReturnResult( 102 utils::RunFunctionAndReturnSingleResult(
103 new GetWindowFunction(), 103 new GetWindowFunction(),
104 base::StringPrintf( 104 base::StringPrintf(
105 "[%u]", ExtensionTabUtil::GetWindowId(panel_browser)), 105 "[%u]", ExtensionTabUtil::GetWindowId(panel_browser)),
106 browser()))); 106 browser())));
107 EXPECT_EQ("panel", utils::GetString(result.get(), "type")); 107 EXPECT_EQ("panel", utils::GetString(result.get(), "type"));
108 108
109 // Incognito. 109 // Incognito.
110 Browser* incognito_browser = CreateIncognitoBrowser(); 110 Browser* incognito_browser = CreateIncognitoBrowser();
111 int incognito_window_id = ExtensionTabUtil::GetWindowId(incognito_browser); 111 int incognito_window_id = ExtensionTabUtil::GetWindowId(incognito_browser);
112 112
113 // Without "include_incognito". 113 // Without "include_incognito".
114 EXPECT_TRUE(MatchPattern( 114 EXPECT_TRUE(MatchPattern(
115 utils::RunFunctionAndReturnError( 115 utils::RunFunctionAndReturnError(
116 new GetWindowFunction(), 116 new GetWindowFunction(),
117 base::StringPrintf("[%u]", incognito_window_id), 117 base::StringPrintf("[%u]", incognito_window_id),
118 browser()), 118 browser()),
119 keys::kWindowNotFoundError)); 119 keys::kWindowNotFoundError));
120 120
121 // With "include_incognito". 121 // With "include_incognito".
122 result.reset(utils::ToDictionary( 122 result.reset(utils::ToDictionary(
123 utils::RunFunctionAndReturnResult( 123 utils::RunFunctionAndReturnSingleResult(
124 new GetWindowFunction(), 124 new GetWindowFunction(),
125 base::StringPrintf("[%u]", incognito_window_id), 125 base::StringPrintf("[%u]", incognito_window_id),
126 browser(), 126 browser(),
127 utils::INCLUDE_INCOGNITO))); 127 utils::INCLUDE_INCOGNITO)));
128 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito")); 128 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito"));
129 } 129 }
130 130
131 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetCurrentWindow) { 131 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetCurrentWindow) {
132 int window_id = ExtensionTabUtil::GetWindowId(browser()); 132 int window_id = ExtensionTabUtil::GetWindowId(browser());
133 Browser* new_browser = CreateBrowser(browser()->profile()); 133 Browser* new_browser = CreateBrowser(browser()->profile());
134 int new_id = ExtensionTabUtil::GetWindowId(new_browser); 134 int new_id = ExtensionTabUtil::GetWindowId(new_browser);
135 135
136 // Get the current window using new_browser. 136 // Get the current window using new_browser.
137 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 137 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary(
138 utils::RunFunctionAndReturnResult( 138 utils::RunFunctionAndReturnSingleResult(
139 new GetCurrentWindowFunction(), 139 new GetCurrentWindowFunction(),
140 "[]", 140 "[]",
141 new_browser))); 141 new_browser)));
142 142
143 // The id should match the window id of the browser instance that was passed 143 // The id should match the window id of the browser instance that was passed
144 // to RunFunctionAndReturnResult. 144 // to RunFunctionAndReturnSingleResult.
145 EXPECT_EQ(new_id, utils::GetInteger(result.get(), "id")); 145 EXPECT_EQ(new_id, utils::GetInteger(result.get(), "id"));
146 ListValue* tabs = NULL; 146 ListValue* tabs = NULL;
147 EXPECT_FALSE(result.get()->GetList(keys::kTabsKey, &tabs)); 147 EXPECT_FALSE(result.get()->GetList(keys::kTabsKey, &tabs));
148 148
149 // Get the current window using the old window and make the tabs populated. 149 // Get the current window using the old window and make the tabs populated.
150 result.reset(utils::ToDictionary( 150 result.reset(utils::ToDictionary(
151 utils::RunFunctionAndReturnResult( 151 utils::RunFunctionAndReturnSingleResult(
152 new GetCurrentWindowFunction(), 152 new GetCurrentWindowFunction(),
153 "[{\"populate\": true}]", 153 "[{\"populate\": true}]",
154 browser()))); 154 browser())));
155 155
156 // The id should match the window id of the browser instance that was passed 156 // The id should match the window id of the browser instance that was passed
157 // to RunFunctionAndReturnResult. 157 // to RunFunctionAndReturnSingleResult.
158 EXPECT_EQ(window_id, utils::GetInteger(result.get(), "id")); 158 EXPECT_EQ(window_id, utils::GetInteger(result.get(), "id"));
159 // "populate" was enabled so tabs should be populated. 159 // "populate" was enabled so tabs should be populated.
160 EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs)); 160 EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs));
161 } 161 }
162 162
163 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetLastFocusedWindow) { 163 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetLastFocusedWindow) {
164 // Create a new window which making it the "last focused" window. 164 // Create a new window which making it the "last focused" window.
165 // Note that "last focused" means the "top" most window. 165 // Note that "last focused" means the "top" most window.
166 Browser* new_browser = CreateBrowser(browser()->profile()); 166 Browser* new_browser = CreateBrowser(browser()->profile());
167 int focused_window_id = ExtensionTabUtil::GetWindowId(new_browser); 167 int focused_window_id = ExtensionTabUtil::GetWindowId(new_browser);
168 168
169 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 169 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary(
170 utils::RunFunctionAndReturnResult( 170 utils::RunFunctionAndReturnSingleResult(
171 new GetLastFocusedWindowFunction(), 171 new GetLastFocusedWindowFunction(),
172 "[]", 172 "[]",
173 new_browser))); 173 new_browser)));
174 174
175 // The id should always match the last focused window and does not depend 175 // The id should always match the last focused window and does not depend
176 // on what was passed to RunFunctionAndReturnResult. 176 // on what was passed to RunFunctionAndReturnSingleResult.
177 EXPECT_EQ(focused_window_id, utils::GetInteger(result.get(), "id")); 177 EXPECT_EQ(focused_window_id, utils::GetInteger(result.get(), "id"));
178 ListValue* tabs = NULL; 178 ListValue* tabs = NULL;
179 EXPECT_FALSE(result.get()->GetList(keys::kTabsKey, &tabs)); 179 EXPECT_FALSE(result.get()->GetList(keys::kTabsKey, &tabs));
180 180
181 result.reset(utils::ToDictionary( 181 result.reset(utils::ToDictionary(
182 utils::RunFunctionAndReturnResult( 182 utils::RunFunctionAndReturnSingleResult(
183 new GetLastFocusedWindowFunction(), 183 new GetLastFocusedWindowFunction(),
184 "[{\"populate\": true}]", 184 "[{\"populate\": true}]",
185 browser()))); 185 browser())));
186 186
187 // The id should always match the last focused window and does not depend 187 // The id should always match the last focused window and does not depend
188 // on what was passed to RunFunctionAndReturnResult. 188 // on what was passed to RunFunctionAndReturnSingleResult.
189 EXPECT_EQ(focused_window_id, utils::GetInteger(result.get(), "id")); 189 EXPECT_EQ(focused_window_id, utils::GetInteger(result.get(), "id"));
190 // "populate" was enabled so tabs should be populated. 190 // "populate" was enabled so tabs should be populated.
191 EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs)); 191 EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs));
192 } 192 }
193 193
194 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetAllWindows) { 194 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetAllWindows) {
195 const size_t NUM_WINDOWS = 5; 195 const size_t NUM_WINDOWS = 5;
196 std::set<int> window_ids; 196 std::set<int> window_ids;
197 std::set<int> result_ids; 197 std::set<int> result_ids;
198 window_ids.insert(ExtensionTabUtil::GetWindowId(browser())); 198 window_ids.insert(ExtensionTabUtil::GetWindowId(browser()));
199 199
200 for (size_t i = 0; i < NUM_WINDOWS - 1; ++i) { 200 for (size_t i = 0; i < NUM_WINDOWS - 1; ++i) {
201 Browser* new_browser = CreateBrowser(browser()->profile()); 201 Browser* new_browser = CreateBrowser(browser()->profile());
202 window_ids.insert(ExtensionTabUtil::GetWindowId(new_browser)); 202 window_ids.insert(ExtensionTabUtil::GetWindowId(new_browser));
203 } 203 }
204 204
205 scoped_ptr<base::ListValue> result(utils::ToList( 205 scoped_ptr<base::ListValue> result(utils::ToList(
206 utils::RunFunctionAndReturnResult( 206 utils::RunFunctionAndReturnSingleResult(
207 new GetAllWindowsFunction(), 207 new GetAllWindowsFunction(),
208 "[]", 208 "[]",
209 browser()))); 209 browser())));
210 210
211 ListValue* windows = result.get(); 211 ListValue* windows = result.get();
212 EXPECT_EQ(NUM_WINDOWS, windows->GetSize()); 212 EXPECT_EQ(NUM_WINDOWS, windows->GetSize());
213 for (size_t i = 0; i < NUM_WINDOWS; ++i) { 213 for (size_t i = 0; i < NUM_WINDOWS; ++i) {
214 DictionaryValue* result_window = NULL; 214 DictionaryValue* result_window = NULL;
215 EXPECT_TRUE(windows->GetDictionary(i, &result_window)); 215 EXPECT_TRUE(windows->GetDictionary(i, &result_window));
216 result_ids.insert(utils::GetInteger(result_window, "id")); 216 result_ids.insert(utils::GetInteger(result_window, "id"));
217 217
218 // "populate" was not passed in so tabs are not populated. 218 // "populate" was not passed in so tabs are not populated.
219 ListValue* tabs = NULL; 219 ListValue* tabs = NULL;
220 EXPECT_FALSE(result_window->GetList(keys::kTabsKey, &tabs)); 220 EXPECT_FALSE(result_window->GetList(keys::kTabsKey, &tabs));
221 } 221 }
222 // The returned ids should contain all the current browser instance ids. 222 // The returned ids should contain all the current browser instance ids.
223 EXPECT_EQ(window_ids, result_ids); 223 EXPECT_EQ(window_ids, result_ids);
224 224
225 result_ids.clear(); 225 result_ids.clear();
226 result.reset(utils::ToList( 226 result.reset(utils::ToList(
227 utils::RunFunctionAndReturnResult( 227 utils::RunFunctionAndReturnSingleResult(
228 new GetAllWindowsFunction(), 228 new GetAllWindowsFunction(),
229 "[{\"populate\": true}]", 229 "[{\"populate\": true}]",
230 browser()))); 230 browser())));
231 231
232 windows = result.get(); 232 windows = result.get();
233 EXPECT_EQ(NUM_WINDOWS, windows->GetSize()); 233 EXPECT_EQ(NUM_WINDOWS, windows->GetSize());
234 for (size_t i = 0; i < windows->GetSize(); ++i) { 234 for (size_t i = 0; i < windows->GetSize(); ++i) {
235 DictionaryValue* result_window = NULL; 235 DictionaryValue* result_window = NULL;
236 EXPECT_TRUE(windows->GetDictionary(i, &result_window)); 236 EXPECT_TRUE(windows->GetDictionary(i, &result_window));
237 result_ids.insert(utils::GetInteger(result_window, "id")); 237 result_ids.insert(utils::GetInteger(result_window, "id"));
238 238
239 // "populate" was enabled so tabs should be populated. 239 // "populate" was enabled so tabs should be populated.
240 ListValue* tabs = NULL; 240 ListValue* tabs = NULL;
241 EXPECT_TRUE(result_window->GetList(keys::kTabsKey, &tabs)); 241 EXPECT_TRUE(result_window->GetList(keys::kTabsKey, &tabs));
242 } 242 }
243 // The returned ids should contain all the current browser instance ids. 243 // The returned ids should contain all the current browser instance ids.
244 EXPECT_EQ(window_ids, result_ids); 244 EXPECT_EQ(window_ids, result_ids);
245 } 245 }
246 246
247 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateNoPermissions) { 247 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateNoPermissions) {
248 // The test empty extension has no permissions, therefore it should not get 248 // The test empty extension has no permissions, therefore it should not get
249 // tab data in the function result. 249 // tab data in the function result.
250 scoped_refptr<UpdateTabFunction> update_tab_function(new UpdateTabFunction()); 250 scoped_refptr<UpdateTabFunction> update_tab_function(new UpdateTabFunction());
251 scoped_refptr<extensions::Extension> empty_extension( 251 scoped_refptr<extensions::Extension> empty_extension(
252 utils::CreateEmptyExtension()); 252 utils::CreateEmptyExtension());
253 update_tab_function->set_extension(empty_extension.get()); 253 update_tab_function->set_extension(empty_extension.get());
254 // Without a callback the function will not generate a result. 254 // Without a callback the function will not generate a result.
255 update_tab_function->set_has_callback(true); 255 update_tab_function->set_has_callback(true);
256 256
257 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnResult( 257 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
258 update_tab_function.get(), 258 update_tab_function.get(),
259 "[null, {\"url\": \"neutrinos\"}]", 259 "[null, {\"url\": \"neutrinos\"}]",
260 browser())); 260 browser()));
261 EXPECT_EQ(base::Value::TYPE_NULL, result->GetType()); 261 EXPECT_EQ(base::Value::TYPE_NULL, result->GetType());
262 } 262 }
263 263
264 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, 264 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest,
265 DefaultToIncognitoWhenItIsForced) { 265 DefaultToIncognitoWhenItIsForced) {
266 static const char kArgsWithoutExplicitIncognitoParam[] = 266 static const char kArgsWithoutExplicitIncognitoParam[] =
267 "[{\"url\": \"about:blank\"}]"; 267 "[{\"url\": \"about:blank\"}]";
268 // Force Incognito mode. 268 // Force Incognito mode.
269 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), 269 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(),
270 IncognitoModePrefs::FORCED); 270 IncognitoModePrefs::FORCED);
271 // Run without an explicit "incognito" param. 271 // Run without an explicit "incognito" param.
272 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 272 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary(
273 utils::RunFunctionAndReturnResult( 273 utils::RunFunctionAndReturnSingleResult(
274 new CreateWindowFunction(), 274 new CreateWindowFunction(),
275 kArgsWithoutExplicitIncognitoParam, 275 kArgsWithoutExplicitIncognitoParam,
276 browser(), 276 browser(),
277 utils::INCLUDE_INCOGNITO))); 277 utils::INCLUDE_INCOGNITO)));
278 278
279 // Make sure it is a new(different) window. 279 // Make sure it is a new(different) window.
280 EXPECT_NE(ExtensionTabUtil::GetWindowId(browser()), 280 EXPECT_NE(ExtensionTabUtil::GetWindowId(browser()),
281 utils::GetInteger(result.get(), "id")); 281 utils::GetInteger(result.get(), "id"));
282 // ... and it is incognito. 282 // ... and it is incognito.
283 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito")); 283 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito"));
284 284
285 // Now try creating a window from incognito window. 285 // Now try creating a window from incognito window.
286 Browser* incognito_browser = CreateIncognitoBrowser(); 286 Browser* incognito_browser = CreateIncognitoBrowser();
287 // Run without an explicit "incognito" param. 287 // Run without an explicit "incognito" param.
288 result.reset(utils::ToDictionary( 288 result.reset(utils::ToDictionary(
289 utils::RunFunctionAndReturnResult( 289 utils::RunFunctionAndReturnSingleResult(
290 new CreateWindowFunction(), 290 new CreateWindowFunction(),
291 kArgsWithoutExplicitIncognitoParam, 291 kArgsWithoutExplicitIncognitoParam,
292 incognito_browser, 292 incognito_browser,
293 utils::INCLUDE_INCOGNITO))); 293 utils::INCLUDE_INCOGNITO)));
294 // Make sure it is a new(different) window. 294 // Make sure it is a new(different) window.
295 EXPECT_NE(ExtensionTabUtil::GetWindowId(incognito_browser), 295 EXPECT_NE(ExtensionTabUtil::GetWindowId(incognito_browser),
296 utils::GetInteger(result.get(), "id")); 296 utils::GetInteger(result.get(), "id"));
297 // ... and it is incognito. 297 // ... and it is incognito.
298 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito")); 298 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito"));
299 } 299 }
300 300
301 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, 301 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest,
302 DefaultToIncognitoWhenItIsForcedAndNoArgs) { 302 DefaultToIncognitoWhenItIsForcedAndNoArgs) {
303 static const char kEmptyArgs[] = "[]"; 303 static const char kEmptyArgs[] = "[]";
304 // Force Incognito mode. 304 // Force Incognito mode.
305 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), 305 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(),
306 IncognitoModePrefs::FORCED); 306 IncognitoModePrefs::FORCED);
307 // Run without an explicit "incognito" param. 307 // Run without an explicit "incognito" param.
308 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 308 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary(
309 utils::RunFunctionAndReturnResult( 309 utils::RunFunctionAndReturnSingleResult(
310 new CreateWindowFunction(), 310 new CreateWindowFunction(),
311 kEmptyArgs, 311 kEmptyArgs,
312 browser(), 312 browser(),
313 utils::INCLUDE_INCOGNITO))); 313 utils::INCLUDE_INCOGNITO)));
314 314
315 // Make sure it is a new(different) window. 315 // Make sure it is a new(different) window.
316 EXPECT_NE(ExtensionTabUtil::GetWindowId(browser()), 316 EXPECT_NE(ExtensionTabUtil::GetWindowId(browser()),
317 utils::GetInteger(result.get(), "id")); 317 utils::GetInteger(result.get(), "id"));
318 // ... and it is incognito. 318 // ... and it is incognito.
319 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito")); 319 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito"));
320 320
321 // Now try creating a window from incognito window. 321 // Now try creating a window from incognito window.
322 Browser* incognito_browser = CreateIncognitoBrowser(); 322 Browser* incognito_browser = CreateIncognitoBrowser();
323 // Run without an explicit "incognito" param. 323 // Run without an explicit "incognito" param.
324 result.reset(utils::ToDictionary( 324 result.reset(utils::ToDictionary(
325 utils::RunFunctionAndReturnResult( 325 utils::RunFunctionAndReturnSingleResult(
326 new CreateWindowFunction(), 326 new CreateWindowFunction(),
327 kEmptyArgs, 327 kEmptyArgs,
328 incognito_browser, 328 incognito_browser,
329 utils::INCLUDE_INCOGNITO))); 329 utils::INCLUDE_INCOGNITO)));
330 // Make sure it is a new(different) window. 330 // Make sure it is a new(different) window.
331 EXPECT_NE(ExtensionTabUtil::GetWindowId(incognito_browser), 331 EXPECT_NE(ExtensionTabUtil::GetWindowId(incognito_browser),
332 utils::GetInteger(result.get(), "id")); 332 utils::GetInteger(result.get(), "id"));
333 // ... and it is incognito. 333 // ... and it is incognito.
334 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito")); 334 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito"));
335 } 335 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 const size_t kExtraWindows = 3; 391 const size_t kExtraWindows = 3;
392 for (size_t i = 0; i < kExtraWindows; ++i) 392 for (size_t i = 0; i < kExtraWindows; ++i)
393 CreateBrowser(browser()->profile()); 393 CreateBrowser(browser()->profile());
394 394
395 GURL url; 395 GURL url;
396 AddTabAtIndexToBrowser(browser(), 0, url, content::PAGE_TRANSITION_LINK); 396 AddTabAtIndexToBrowser(browser(), 0, url, content::PAGE_TRANSITION_LINK);
397 int window_id = ExtensionTabUtil::GetWindowId(browser()); 397 int window_id = ExtensionTabUtil::GetWindowId(browser());
398 398
399 // Get tabs in the 'current' window called from non-focused browser. 399 // Get tabs in the 'current' window called from non-focused browser.
400 scoped_ptr<base::ListValue> result(utils::ToList( 400 scoped_ptr<base::ListValue> result(utils::ToList(
401 utils::RunFunctionAndReturnResult( 401 utils::RunFunctionAndReturnSingleResult(
402 new QueryTabsFunction(), 402 new QueryTabsFunction(),
403 "[{\"currentWindow\":true}]", 403 "[{\"currentWindow\":true}]",
404 browser()))); 404 browser())));
405 405
406 ListValue* result_tabs = result.get(); 406 ListValue* result_tabs = result.get();
407 // We should have one initial tab and one added tab. 407 // We should have one initial tab and one added tab.
408 EXPECT_EQ(2u, result_tabs->GetSize()); 408 EXPECT_EQ(2u, result_tabs->GetSize());
409 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { 409 for (size_t i = 0; i < result_tabs->GetSize(); ++i) {
410 DictionaryValue* result_tab = NULL; 410 DictionaryValue* result_tab = NULL;
411 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); 411 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab));
412 EXPECT_EQ(window_id, utils::GetInteger(result_tab, keys::kWindowIdKey)); 412 EXPECT_EQ(window_id, utils::GetInteger(result_tab, keys::kWindowIdKey));
413 } 413 }
414 414
415 // Get tabs NOT in the 'current' window called from non-focused browser. 415 // Get tabs NOT in the 'current' window called from non-focused browser.
416 result.reset(utils::ToList( 416 result.reset(utils::ToList(
417 utils::RunFunctionAndReturnResult( 417 utils::RunFunctionAndReturnSingleResult(
418 new QueryTabsFunction(), 418 new QueryTabsFunction(),
419 "[{\"currentWindow\":false}]", 419 "[{\"currentWindow\":false}]",
420 browser()))); 420 browser())));
421 421
422 result_tabs = result.get(); 422 result_tabs = result.get();
423 // We should have one tab for each extra window. 423 // We should have one tab for each extra window.
424 EXPECT_EQ(kExtraWindows, result_tabs->GetSize()); 424 EXPECT_EQ(kExtraWindows, result_tabs->GetSize());
425 for (size_t i = 0; i < kExtraWindows; ++i) { 425 for (size_t i = 0; i < kExtraWindows; ++i) {
426 DictionaryValue* result_tab = NULL; 426 DictionaryValue* result_tab = NULL;
427 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); 427 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab));
(...skipping 17 matching lines...) Expand all
445 445
446 // Needed on Mac and Linux so that the BrowserWindow::IsActive calls work. 446 // Needed on Mac and Linux so that the BrowserWindow::IsActive calls work.
447 ui_test_utils::RunAllPendingInMessageLoop(); 447 ui_test_utils::RunAllPendingInMessageLoop();
448 448
449 GURL url; 449 GURL url;
450 AddTabAtIndexToBrowser(focused_window, 0, url, content::PAGE_TRANSITION_LINK); 450 AddTabAtIndexToBrowser(focused_window, 0, url, content::PAGE_TRANSITION_LINK);
451 int focused_window_id = ExtensionTabUtil::GetWindowId(focused_window); 451 int focused_window_id = ExtensionTabUtil::GetWindowId(focused_window);
452 452
453 // Get tabs in the 'last focused' window called from non-focused browser. 453 // Get tabs in the 'last focused' window called from non-focused browser.
454 scoped_ptr<base::ListValue> result(utils::ToList( 454 scoped_ptr<base::ListValue> result(utils::ToList(
455 utils::RunFunctionAndReturnResult( 455 utils::RunFunctionAndReturnSingleResult(
456 new QueryTabsFunction(), 456 new QueryTabsFunction(),
457 "[{\"lastFocusedWindow\":true}]", 457 "[{\"lastFocusedWindow\":true}]",
458 browser()))); 458 browser())));
459 459
460 ListValue* result_tabs = result.get(); 460 ListValue* result_tabs = result.get();
461 // We should have one initial tab and one added tab. 461 // We should have one initial tab and one added tab.
462 EXPECT_EQ(2u, result_tabs->GetSize()); 462 EXPECT_EQ(2u, result_tabs->GetSize());
463 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { 463 for (size_t i = 0; i < result_tabs->GetSize(); ++i) {
464 DictionaryValue* result_tab = NULL; 464 DictionaryValue* result_tab = NULL;
465 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); 465 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab));
466 EXPECT_EQ(focused_window_id, utils::GetInteger(result_tab, 466 EXPECT_EQ(focused_window_id, utils::GetInteger(result_tab,
467 keys::kWindowIdKey)); 467 keys::kWindowIdKey));
468 } 468 }
469 469
470 // Get tabs NOT in the 'last focused' window called from the focused browser. 470 // Get tabs NOT in the 'last focused' window called from the focused browser.
471 result.reset(utils::ToList( 471 result.reset(utils::ToList(
472 utils::RunFunctionAndReturnResult( 472 utils::RunFunctionAndReturnSingleResult(
473 new QueryTabsFunction(), 473 new QueryTabsFunction(),
474 "[{\"lastFocusedWindow\":false}]", 474 "[{\"lastFocusedWindow\":false}]",
475 browser()))); 475 browser())));
476 476
477 result_tabs = result.get(); 477 result_tabs = result.get();
478 // We should get one tab for each extra window and one for the initial window. 478 // We should get one tab for each extra window and one for the initial window.
479 EXPECT_EQ(kExtraWindows + 1, result_tabs->GetSize()); 479 EXPECT_EQ(kExtraWindows + 1, result_tabs->GetSize());
480 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { 480 for (size_t i = 0; i < result_tabs->GetSize(); ++i) {
481 DictionaryValue* result_tab = NULL; 481 DictionaryValue* result_tab = NULL;
482 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); 482 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab));
(...skipping 12 matching lines...) Expand all
495 chrome::CloseWindow(popup_browser); 495 chrome::CloseWindow(popup_browser);
496 496
497 scoped_refptr<CreateTabFunction> create_tab_function(new CreateTabFunction()); 497 scoped_refptr<CreateTabFunction> create_tab_function(new CreateTabFunction());
498 // Without a callback the function will not generate a result. 498 // Without a callback the function will not generate a result.
499 create_tab_function->set_has_callback(true); 499 create_tab_function->set_has_callback(true);
500 500
501 static const char kNewBlankTabArgs[] = 501 static const char kNewBlankTabArgs[] =
502 "[{\"url\": \"about:blank\", \"windowId\": %u}]"; 502 "[{\"url\": \"about:blank\", \"windowId\": %u}]";
503 503
504 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 504 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary(
505 utils::RunFunctionAndReturnResult( 505 utils::RunFunctionAndReturnSingleResult(
506 create_tab_function.get(), 506 create_tab_function.get(),
507 base::StringPrintf(kNewBlankTabArgs, window_id), 507 base::StringPrintf(kNewBlankTabArgs, window_id),
508 browser()))); 508 browser())));
509 509
510 EXPECT_NE(window_id, utils::GetInteger(result.get(), "windowId")); 510 EXPECT_NE(window_id, utils::GetInteger(result.get(), "windowId"));
511 } 511 }
512 512
513 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, InvalidUpdateWindowState) { 513 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, InvalidUpdateWindowState) {
514 int window_id = ExtensionTabUtil::GetWindowId(browser()); 514 int window_id = ExtensionTabUtil::GetWindowId(browser());
515 515
(...skipping 26 matching lines...) Expand all
542 542
543 static const char kArgsMaximizedWithBounds[] = 543 static const char kArgsMaximizedWithBounds[] =
544 "[%u, {\"state\": \"maximized\", \"width\": 500}]"; 544 "[%u, {\"state\": \"maximized\", \"width\": 500}]";
545 EXPECT_TRUE(MatchPattern( 545 EXPECT_TRUE(MatchPattern(
546 utils::RunFunctionAndReturnError( 546 utils::RunFunctionAndReturnError(
547 new UpdateWindowFunction(), 547 new UpdateWindowFunction(),
548 base::StringPrintf(kArgsMaximizedWithBounds, window_id), 548 base::StringPrintf(kArgsMaximizedWithBounds, window_id),
549 browser()), 549 browser()),
550 keys::kInvalidWindowStateError)); 550 keys::kInvalidWindowStateError));
551 } 551 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698