| OLD | NEW |
| 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 | 5 |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/extensions/api/tabs/tabs_api.h" | 14 #include "chrome/browser/extensions/api/tabs/tabs_api.h" |
| 15 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 15 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| 16 #include "chrome/browser/extensions/extension_function_test_utils.h" | 16 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 17 #include "chrome/browser/extensions/extension_tab_util.h" | 17 #include "chrome/browser/extensions/extension_tab_util.h" |
| 18 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 18 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/browser/ui/browser_commands.h" | 21 #include "chrome/browser/ui/browser_commands.h" |
| 22 #include "chrome/browser/ui/browser_window.h" | 22 #include "chrome/browser/ui/browser_window.h" |
| 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 24 #include "chrome/test/base/in_process_browser_test.h" | 24 #include "chrome/test/base/in_process_browser_test.h" |
| 25 #include "chrome/test/base/ui_test_utils.h" | 25 #include "chrome/test/base/ui_test_utils.h" |
| 26 #include "content/public/common/page_zoom.h" | 26 #include "content/public/common/page_zoom.h" |
| 27 #include "content/public/common/url_constants.h" | 27 #include "content/public/common/url_constants.h" |
| 28 #include "extensions/common/manifest_constants.h" | 28 #include "extensions/common/manifest_constants.h" |
| 29 #include "extensions/common/test_util.h" |
| 29 #include "ui/gfx/rect.h" | 30 #include "ui/gfx/rect.h" |
| 30 | 31 |
| 31 namespace extensions { | 32 namespace extensions { |
| 32 | 33 |
| 33 namespace keys = tabs_constants; | 34 namespace keys = tabs_constants; |
| 34 namespace utils = extension_function_test_utils; | 35 namespace utils = extension_function_test_utils; |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 38 class ExtensionTabsTest : public InProcessBrowserTest { | 39 class ExtensionTabsTest : public InProcessBrowserTest { |
| 39 }; | 40 }; |
| 40 | 41 |
| 41 } | 42 } |
| 42 | 43 |
| 43 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetWindow) { | 44 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetWindow) { |
| 44 int window_id = ExtensionTabUtil::GetWindowId(browser()); | 45 int window_id = ExtensionTabUtil::GetWindowId(browser()); |
| 45 | 46 |
| 46 // Invalid window ID error. | 47 // Invalid window ID error. |
| 47 scoped_refptr<WindowsGetFunction> function = new WindowsGetFunction(); | 48 scoped_refptr<WindowsGetFunction> function = new WindowsGetFunction(); |
| 48 scoped_refptr<Extension> extension(utils::CreateEmptyExtension()); | 49 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); |
| 49 function->set_extension(extension.get()); | 50 function->set_extension(extension.get()); |
| 50 EXPECT_TRUE(MatchPattern( | 51 EXPECT_TRUE(MatchPattern( |
| 51 utils::RunFunctionAndReturnError( | 52 utils::RunFunctionAndReturnError( |
| 52 function.get(), | 53 function.get(), |
| 53 base::StringPrintf("[%u]", window_id + 1), | 54 base::StringPrintf("[%u]", window_id + 1), |
| 54 browser()), | 55 browser()), |
| 55 keys::kWindowNotFoundError)); | 56 keys::kWindowNotFoundError)); |
| 56 | 57 |
| 57 // Basic window details. | 58 // Basic window details. |
| 58 gfx::Rect bounds; | 59 gfx::Rect bounds; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 } | 141 } |
| 141 | 142 |
| 142 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetCurrentWindow) { | 143 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetCurrentWindow) { |
| 143 int window_id = ExtensionTabUtil::GetWindowId(browser()); | 144 int window_id = ExtensionTabUtil::GetWindowId(browser()); |
| 144 Browser* new_browser = CreateBrowser(browser()->profile()); | 145 Browser* new_browser = CreateBrowser(browser()->profile()); |
| 145 int new_id = ExtensionTabUtil::GetWindowId(new_browser); | 146 int new_id = ExtensionTabUtil::GetWindowId(new_browser); |
| 146 | 147 |
| 147 // Get the current window using new_browser. | 148 // Get the current window using new_browser. |
| 148 scoped_refptr<WindowsGetCurrentFunction> function = | 149 scoped_refptr<WindowsGetCurrentFunction> function = |
| 149 new WindowsGetCurrentFunction(); | 150 new WindowsGetCurrentFunction(); |
| 150 scoped_refptr<Extension> extension(utils::CreateEmptyExtension()); | 151 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); |
| 151 function->set_extension(extension.get()); | 152 function->set_extension(extension.get()); |
| 152 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( | 153 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( |
| 153 utils::RunFunctionAndReturnSingleResult(function.get(), | 154 utils::RunFunctionAndReturnSingleResult(function.get(), |
| 154 "[]", | 155 "[]", |
| 155 new_browser))); | 156 new_browser))); |
| 156 | 157 |
| 157 // The id should match the window id of the browser instance that was passed | 158 // The id should match the window id of the browser instance that was passed |
| 158 // to RunFunctionAndReturnSingleResult. | 159 // to RunFunctionAndReturnSingleResult. |
| 159 EXPECT_EQ(new_id, utils::GetInteger(result.get(), "id")); | 160 EXPECT_EQ(new_id, utils::GetInteger(result.get(), "id")); |
| 160 base::ListValue* tabs = NULL; | 161 base::ListValue* tabs = NULL; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 180 std::set<int> window_ids; | 181 std::set<int> window_ids; |
| 181 std::set<int> result_ids; | 182 std::set<int> result_ids; |
| 182 window_ids.insert(ExtensionTabUtil::GetWindowId(browser())); | 183 window_ids.insert(ExtensionTabUtil::GetWindowId(browser())); |
| 183 | 184 |
| 184 for (size_t i = 0; i < NUM_WINDOWS - 1; ++i) { | 185 for (size_t i = 0; i < NUM_WINDOWS - 1; ++i) { |
| 185 Browser* new_browser = CreateBrowser(browser()->profile()); | 186 Browser* new_browser = CreateBrowser(browser()->profile()); |
| 186 window_ids.insert(ExtensionTabUtil::GetWindowId(new_browser)); | 187 window_ids.insert(ExtensionTabUtil::GetWindowId(new_browser)); |
| 187 } | 188 } |
| 188 | 189 |
| 189 scoped_refptr<WindowsGetAllFunction> function = new WindowsGetAllFunction(); | 190 scoped_refptr<WindowsGetAllFunction> function = new WindowsGetAllFunction(); |
| 190 scoped_refptr<Extension> extension(utils::CreateEmptyExtension()); | 191 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); |
| 191 function->set_extension(extension.get()); | 192 function->set_extension(extension.get()); |
| 192 scoped_ptr<base::ListValue> result(utils::ToList( | 193 scoped_ptr<base::ListValue> result(utils::ToList( |
| 193 utils::RunFunctionAndReturnSingleResult(function.get(), | 194 utils::RunFunctionAndReturnSingleResult(function.get(), |
| 194 "[]", | 195 "[]", |
| 195 browser()))); | 196 browser()))); |
| 196 | 197 |
| 197 base::ListValue* windows = result.get(); | 198 base::ListValue* windows = result.get(); |
| 198 EXPECT_EQ(NUM_WINDOWS, windows->GetSize()); | 199 EXPECT_EQ(NUM_WINDOWS, windows->GetSize()); |
| 199 for (size_t i = 0; i < NUM_WINDOWS; ++i) { | 200 for (size_t i = 0; i < NUM_WINDOWS; ++i) { |
| 200 base::DictionaryValue* result_window = NULL; | 201 base::DictionaryValue* result_window = NULL; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 229 } | 230 } |
| 230 // The returned ids should contain all the current browser instance ids. | 231 // The returned ids should contain all the current browser instance ids. |
| 231 EXPECT_EQ(window_ids, result_ids); | 232 EXPECT_EQ(window_ids, result_ids); |
| 232 } | 233 } |
| 233 | 234 |
| 234 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateNoPermissions) { | 235 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateNoPermissions) { |
| 235 // The test empty extension has no permissions, therefore it should not get | 236 // The test empty extension has no permissions, therefore it should not get |
| 236 // tab data in the function result. | 237 // tab data in the function result. |
| 237 scoped_refptr<TabsUpdateFunction> update_tab_function( | 238 scoped_refptr<TabsUpdateFunction> update_tab_function( |
| 238 new TabsUpdateFunction()); | 239 new TabsUpdateFunction()); |
| 239 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); | 240 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension()); |
| 240 update_tab_function->set_extension(empty_extension.get()); | 241 update_tab_function->set_extension(empty_extension.get()); |
| 241 // Without a callback the function will not generate a result. | 242 // Without a callback the function will not generate a result. |
| 242 update_tab_function->set_has_callback(true); | 243 update_tab_function->set_has_callback(true); |
| 243 | 244 |
| 244 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( | 245 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( |
| 245 utils::RunFunctionAndReturnSingleResult( | 246 utils::RunFunctionAndReturnSingleResult( |
| 246 update_tab_function.get(), | 247 update_tab_function.get(), |
| 247 "[null, {\"url\": \"about:blank\", \"pinned\": true}]", | 248 "[null, {\"url\": \"about:blank\", \"pinned\": true}]", |
| 248 browser()))); | 249 browser()))); |
| 249 // The url is stripped since the extension does not have tab permissions. | 250 // The url is stripped since the extension does not have tab permissions. |
| 250 EXPECT_FALSE(result->HasKey("url")); | 251 EXPECT_FALSE(result->HasKey("url")); |
| 251 EXPECT_TRUE(utils::GetBoolean(result.get(), "pinned")); | 252 EXPECT_TRUE(utils::GetBoolean(result.get(), "pinned")); |
| 252 } | 253 } |
| 253 | 254 |
| 254 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, | 255 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, |
| 255 DefaultToIncognitoWhenItIsForced) { | 256 DefaultToIncognitoWhenItIsForced) { |
| 256 static const char kArgsWithoutExplicitIncognitoParam[] = | 257 static const char kArgsWithoutExplicitIncognitoParam[] = |
| 257 "[{\"url\": \"about:blank\"}]"; | 258 "[{\"url\": \"about:blank\"}]"; |
| 258 // Force Incognito mode. | 259 // Force Incognito mode. |
| 259 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), | 260 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), |
| 260 IncognitoModePrefs::FORCED); | 261 IncognitoModePrefs::FORCED); |
| 261 // Run without an explicit "incognito" param. | 262 // Run without an explicit "incognito" param. |
| 262 scoped_refptr<WindowsCreateFunction> function(new WindowsCreateFunction()); | 263 scoped_refptr<WindowsCreateFunction> function(new WindowsCreateFunction()); |
| 263 scoped_refptr<Extension> extension(utils::CreateEmptyExtension()); | 264 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); |
| 264 function->set_extension(extension.get()); | 265 function->set_extension(extension.get()); |
| 265 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( | 266 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( |
| 266 utils::RunFunctionAndReturnSingleResult( | 267 utils::RunFunctionAndReturnSingleResult( |
| 267 function.get(), | 268 function.get(), |
| 268 kArgsWithoutExplicitIncognitoParam, | 269 kArgsWithoutExplicitIncognitoParam, |
| 269 browser(), | 270 browser(), |
| 270 utils::INCLUDE_INCOGNITO))); | 271 utils::INCLUDE_INCOGNITO))); |
| 271 | 272 |
| 272 // Make sure it is a new(different) window. | 273 // Make sure it is a new(different) window. |
| 273 EXPECT_NE(ExtensionTabUtil::GetWindowId(browser()), | 274 EXPECT_NE(ExtensionTabUtil::GetWindowId(browser()), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 294 } | 295 } |
| 295 | 296 |
| 296 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, | 297 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, |
| 297 DefaultToIncognitoWhenItIsForcedAndNoArgs) { | 298 DefaultToIncognitoWhenItIsForcedAndNoArgs) { |
| 298 static const char kEmptyArgs[] = "[]"; | 299 static const char kEmptyArgs[] = "[]"; |
| 299 // Force Incognito mode. | 300 // Force Incognito mode. |
| 300 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), | 301 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), |
| 301 IncognitoModePrefs::FORCED); | 302 IncognitoModePrefs::FORCED); |
| 302 // Run without an explicit "incognito" param. | 303 // Run without an explicit "incognito" param. |
| 303 scoped_refptr<WindowsCreateFunction> function = new WindowsCreateFunction(); | 304 scoped_refptr<WindowsCreateFunction> function = new WindowsCreateFunction(); |
| 304 scoped_refptr<Extension> extension(utils::CreateEmptyExtension()); | 305 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); |
| 305 function->set_extension(extension.get()); | 306 function->set_extension(extension.get()); |
| 306 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( | 307 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( |
| 307 utils::RunFunctionAndReturnSingleResult(function.get(), | 308 utils::RunFunctionAndReturnSingleResult(function.get(), |
| 308 kEmptyArgs, | 309 kEmptyArgs, |
| 309 browser(), | 310 browser(), |
| 310 utils::INCLUDE_INCOGNITO))); | 311 utils::INCLUDE_INCOGNITO))); |
| 311 | 312 |
| 312 // Make sure it is a new(different) window. | 313 // Make sure it is a new(different) window. |
| 313 EXPECT_NE(ExtensionTabUtil::GetWindowId(browser()), | 314 EXPECT_NE(ExtensionTabUtil::GetWindowId(browser()), |
| 314 utils::GetInteger(result.get(), "id")); | 315 utils::GetInteger(result.get(), "id")); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 335 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, | 336 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, |
| 336 DontCreateNormalWindowWhenIncognitoForced) { | 337 DontCreateNormalWindowWhenIncognitoForced) { |
| 337 static const char kArgsWithExplicitIncognitoParam[] = | 338 static const char kArgsWithExplicitIncognitoParam[] = |
| 338 "[{\"url\": \"about:blank\", \"incognito\": false }]"; | 339 "[{\"url\": \"about:blank\", \"incognito\": false }]"; |
| 339 // Force Incognito mode. | 340 // Force Incognito mode. |
| 340 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), | 341 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), |
| 341 IncognitoModePrefs::FORCED); | 342 IncognitoModePrefs::FORCED); |
| 342 | 343 |
| 343 // Run with an explicit "incognito" param. | 344 // Run with an explicit "incognito" param. |
| 344 scoped_refptr<WindowsCreateFunction> function = new WindowsCreateFunction(); | 345 scoped_refptr<WindowsCreateFunction> function = new WindowsCreateFunction(); |
| 345 scoped_refptr<Extension> extension(utils::CreateEmptyExtension()); | 346 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); |
| 346 function->set_extension(extension.get()); | 347 function->set_extension(extension.get()); |
| 347 EXPECT_TRUE(MatchPattern( | 348 EXPECT_TRUE(MatchPattern( |
| 348 utils::RunFunctionAndReturnError(function.get(), | 349 utils::RunFunctionAndReturnError(function.get(), |
| 349 kArgsWithExplicitIncognitoParam, | 350 kArgsWithExplicitIncognitoParam, |
| 350 browser()), | 351 browser()), |
| 351 keys::kIncognitoModeIsForced)); | 352 keys::kIncognitoModeIsForced)); |
| 352 | 353 |
| 353 // Now try opening a normal window from incognito window. | 354 // Now try opening a normal window from incognito window. |
| 354 Browser* incognito_browser = CreateIncognitoBrowser(); | 355 Browser* incognito_browser = CreateIncognitoBrowser(); |
| 355 // Run with an explicit "incognito" param. | 356 // Run with an explicit "incognito" param. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 366 DontCreateIncognitoWindowWhenIncognitoDisabled) { | 367 DontCreateIncognitoWindowWhenIncognitoDisabled) { |
| 367 static const char kArgs[] = | 368 static const char kArgs[] = |
| 368 "[{\"url\": \"about:blank\", \"incognito\": true }]"; | 369 "[{\"url\": \"about:blank\", \"incognito\": true }]"; |
| 369 | 370 |
| 370 Browser* incognito_browser = CreateIncognitoBrowser(); | 371 Browser* incognito_browser = CreateIncognitoBrowser(); |
| 371 // Disable Incognito mode. | 372 // Disable Incognito mode. |
| 372 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), | 373 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), |
| 373 IncognitoModePrefs::DISABLED); | 374 IncognitoModePrefs::DISABLED); |
| 374 // Run in normal window. | 375 // Run in normal window. |
| 375 scoped_refptr<WindowsCreateFunction> function = new WindowsCreateFunction(); | 376 scoped_refptr<WindowsCreateFunction> function = new WindowsCreateFunction(); |
| 376 scoped_refptr<Extension> extension(utils::CreateEmptyExtension()); | 377 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); |
| 377 function->set_extension(extension.get()); | 378 function->set_extension(extension.get()); |
| 378 EXPECT_TRUE(MatchPattern( | 379 EXPECT_TRUE(MatchPattern( |
| 379 utils::RunFunctionAndReturnError(function.get(), | 380 utils::RunFunctionAndReturnError(function.get(), |
| 380 kArgs, | 381 kArgs, |
| 381 browser()), | 382 browser()), |
| 382 keys::kIncognitoModeIsDisabled)); | 383 keys::kIncognitoModeIsDisabled)); |
| 383 | 384 |
| 384 // Run in incognito window. | 385 // Run in incognito window. |
| 385 function = new WindowsCreateFunction(); | 386 function = new WindowsCreateFunction(); |
| 386 function->set_extension(extension.get()); | 387 function->set_extension(extension.get()); |
| 387 EXPECT_TRUE(MatchPattern( | 388 EXPECT_TRUE(MatchPattern( |
| 388 utils::RunFunctionAndReturnError(function.get(), | 389 utils::RunFunctionAndReturnError(function.get(), |
| 389 kArgs, | 390 kArgs, |
| 390 incognito_browser), | 391 incognito_browser), |
| 391 keys::kIncognitoModeIsDisabled)); | 392 keys::kIncognitoModeIsDisabled)); |
| 392 } | 393 } |
| 393 | 394 |
| 394 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, QueryCurrentWindowTabs) { | 395 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, QueryCurrentWindowTabs) { |
| 395 const size_t kExtraWindows = 3; | 396 const size_t kExtraWindows = 3; |
| 396 for (size_t i = 0; i < kExtraWindows; ++i) | 397 for (size_t i = 0; i < kExtraWindows; ++i) |
| 397 CreateBrowser(browser()->profile()); | 398 CreateBrowser(browser()->profile()); |
| 398 | 399 |
| 399 GURL url(url::kAboutBlankURL); | 400 GURL url(url::kAboutBlankURL); |
| 400 AddTabAtIndexToBrowser(browser(), 0, url, content::PAGE_TRANSITION_LINK); | 401 AddTabAtIndexToBrowser(browser(), 0, url, content::PAGE_TRANSITION_LINK); |
| 401 int window_id = ExtensionTabUtil::GetWindowId(browser()); | 402 int window_id = ExtensionTabUtil::GetWindowId(browser()); |
| 402 | 403 |
| 403 // Get tabs in the 'current' window called from non-focused browser. | 404 // Get tabs in the 'current' window called from non-focused browser. |
| 404 scoped_refptr<TabsQueryFunction> function = new TabsQueryFunction(); | 405 scoped_refptr<TabsQueryFunction> function = new TabsQueryFunction(); |
| 405 function->set_extension(utils::CreateEmptyExtension().get()); | 406 function->set_extension(test_util::CreateEmptyExtension().get()); |
| 406 scoped_ptr<base::ListValue> result(utils::ToList( | 407 scoped_ptr<base::ListValue> result(utils::ToList( |
| 407 utils::RunFunctionAndReturnSingleResult(function.get(), | 408 utils::RunFunctionAndReturnSingleResult(function.get(), |
| 408 "[{\"currentWindow\":true}]", | 409 "[{\"currentWindow\":true}]", |
| 409 browser()))); | 410 browser()))); |
| 410 | 411 |
| 411 base::ListValue* result_tabs = result.get(); | 412 base::ListValue* result_tabs = result.get(); |
| 412 // We should have one initial tab and one added tab. | 413 // We should have one initial tab and one added tab. |
| 413 EXPECT_EQ(2u, result_tabs->GetSize()); | 414 EXPECT_EQ(2u, result_tabs->GetSize()); |
| 414 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { | 415 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { |
| 415 base::DictionaryValue* result_tab = NULL; | 416 base::DictionaryValue* result_tab = NULL; |
| 416 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); | 417 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); |
| 417 EXPECT_EQ(window_id, utils::GetInteger(result_tab, keys::kWindowIdKey)); | 418 EXPECT_EQ(window_id, utils::GetInteger(result_tab, keys::kWindowIdKey)); |
| 418 } | 419 } |
| 419 | 420 |
| 420 // Get tabs NOT in the 'current' window called from non-focused browser. | 421 // Get tabs NOT in the 'current' window called from non-focused browser. |
| 421 function = new TabsQueryFunction(); | 422 function = new TabsQueryFunction(); |
| 422 function->set_extension(utils::CreateEmptyExtension().get()); | 423 function->set_extension(test_util::CreateEmptyExtension().get()); |
| 423 result.reset(utils::ToList( | 424 result.reset(utils::ToList( |
| 424 utils::RunFunctionAndReturnSingleResult(function.get(), | 425 utils::RunFunctionAndReturnSingleResult(function.get(), |
| 425 "[{\"currentWindow\":false}]", | 426 "[{\"currentWindow\":false}]", |
| 426 browser()))); | 427 browser()))); |
| 427 | 428 |
| 428 result_tabs = result.get(); | 429 result_tabs = result.get(); |
| 429 // We should have one tab for each extra window. | 430 // We should have one tab for each extra window. |
| 430 EXPECT_EQ(kExtraWindows, result_tabs->GetSize()); | 431 EXPECT_EQ(kExtraWindows, result_tabs->GetSize()); |
| 431 for (size_t i = 0; i < kExtraWindows; ++i) { | 432 for (size_t i = 0; i < kExtraWindows; ++i) { |
| 432 base::DictionaryValue* result_tab = NULL; | 433 base::DictionaryValue* result_tab = NULL; |
| 433 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); | 434 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); |
| 434 EXPECT_NE(window_id, utils::GetInteger(result_tab, keys::kWindowIdKey)); | 435 EXPECT_NE(window_id, utils::GetInteger(result_tab, keys::kWindowIdKey)); |
| 435 } | 436 } |
| 436 } | 437 } |
| 437 | 438 |
| 438 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DontCreateTabInClosingPopupWindow) { | 439 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DontCreateTabInClosingPopupWindow) { |
| 439 // Test creates new popup window, closes it right away and then tries to open | 440 // Test creates new popup window, closes it right away and then tries to open |
| 440 // a new tab in it. Tab should not be opened in the popup window, but in a | 441 // a new tab in it. Tab should not be opened in the popup window, but in a |
| 441 // tabbed browser window. | 442 // tabbed browser window. |
| 442 Browser* popup_browser = new Browser( | 443 Browser* popup_browser = new Browser( |
| 443 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile(), | 444 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile(), |
| 444 browser()->host_desktop_type())); | 445 browser()->host_desktop_type())); |
| 445 int window_id = ExtensionTabUtil::GetWindowId(popup_browser); | 446 int window_id = ExtensionTabUtil::GetWindowId(popup_browser); |
| 446 chrome::CloseWindow(popup_browser); | 447 chrome::CloseWindow(popup_browser); |
| 447 | 448 |
| 448 scoped_refptr<TabsCreateFunction> create_tab_function( | 449 scoped_refptr<TabsCreateFunction> create_tab_function( |
| 449 new TabsCreateFunction()); | 450 new TabsCreateFunction()); |
| 450 create_tab_function->set_extension(utils::CreateEmptyExtension().get()); | 451 create_tab_function->set_extension(test_util::CreateEmptyExtension().get()); |
| 451 // Without a callback the function will not generate a result. | 452 // Without a callback the function will not generate a result. |
| 452 create_tab_function->set_has_callback(true); | 453 create_tab_function->set_has_callback(true); |
| 453 | 454 |
| 454 static const char kNewBlankTabArgs[] = | 455 static const char kNewBlankTabArgs[] = |
| 455 "[{\"url\": \"about:blank\", \"windowId\": %u}]"; | 456 "[{\"url\": \"about:blank\", \"windowId\": %u}]"; |
| 456 | 457 |
| 457 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( | 458 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( |
| 458 utils::RunFunctionAndReturnSingleResult( | 459 utils::RunFunctionAndReturnSingleResult( |
| 459 create_tab_function.get(), | 460 create_tab_function.get(), |
| 460 base::StringPrintf(kNewBlankTabArgs, window_id), | 461 base::StringPrintf(kNewBlankTabArgs, window_id), |
| 461 browser()))); | 462 browser()))); |
| 462 | 463 |
| 463 EXPECT_NE(window_id, utils::GetInteger(result.get(), "windowId")); | 464 EXPECT_NE(window_id, utils::GetInteger(result.get(), "windowId")); |
| 464 } | 465 } |
| 465 | 466 |
| 466 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, InvalidUpdateWindowState) { | 467 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, InvalidUpdateWindowState) { |
| 467 int window_id = ExtensionTabUtil::GetWindowId(browser()); | 468 int window_id = ExtensionTabUtil::GetWindowId(browser()); |
| 468 | 469 |
| 469 static const char kArgsMinimizedWithFocus[] = | 470 static const char kArgsMinimizedWithFocus[] = |
| 470 "[%u, {\"state\": \"minimized\", \"focused\": true}]"; | 471 "[%u, {\"state\": \"minimized\", \"focused\": true}]"; |
| 471 scoped_refptr<WindowsUpdateFunction> function = new WindowsUpdateFunction(); | 472 scoped_refptr<WindowsUpdateFunction> function = new WindowsUpdateFunction(); |
| 472 scoped_refptr<Extension> extension(utils::CreateEmptyExtension()); | 473 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); |
| 473 function->set_extension(extension.get()); | 474 function->set_extension(extension.get()); |
| 474 EXPECT_TRUE(MatchPattern( | 475 EXPECT_TRUE(MatchPattern( |
| 475 utils::RunFunctionAndReturnError( | 476 utils::RunFunctionAndReturnError( |
| 476 function.get(), | 477 function.get(), |
| 477 base::StringPrintf(kArgsMinimizedWithFocus, window_id), | 478 base::StringPrintf(kArgsMinimizedWithFocus, window_id), |
| 478 browser()), | 479 browser()), |
| 479 keys::kInvalidWindowStateError)); | 480 keys::kInvalidWindowStateError)); |
| 480 | 481 |
| 481 static const char kArgsMaximizedWithoutFocus[] = | 482 static const char kArgsMaximizedWithoutFocus[] = |
| 482 "[%u, {\"state\": \"maximized\", \"focused\": false}]"; | 483 "[%u, {\"state\": \"maximized\", \"focused\": false}]"; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 false); | 565 false); |
| 565 content::WebContents* web_contents = browser()->OpenURL(params); | 566 content::WebContents* web_contents = browser()->OpenURL(params); |
| 566 int tab_id = ExtensionTabUtil::GetTabId(web_contents); | 567 int tab_id = ExtensionTabUtil::GetTabId(web_contents); |
| 567 int window_id = ExtensionTabUtil::GetWindowIdOfTab(web_contents); | 568 int window_id = ExtensionTabUtil::GetWindowIdOfTab(web_contents); |
| 568 int tab_index = -1; | 569 int tab_index = -1; |
| 569 TabStripModel* tab_strip; | 570 TabStripModel* tab_strip; |
| 570 ExtensionTabUtil::GetTabStripModel(web_contents, &tab_strip, &tab_index); | 571 ExtensionTabUtil::GetTabStripModel(web_contents, &tab_strip, &tab_index); |
| 571 | 572 |
| 572 scoped_refptr<TabsDuplicateFunction> duplicate_tab_function( | 573 scoped_refptr<TabsDuplicateFunction> duplicate_tab_function( |
| 573 new TabsDuplicateFunction()); | 574 new TabsDuplicateFunction()); |
| 574 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); | 575 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension()); |
| 575 duplicate_tab_function->set_extension(empty_extension.get()); | 576 duplicate_tab_function->set_extension(empty_extension.get()); |
| 576 duplicate_tab_function->set_has_callback(true); | 577 duplicate_tab_function->set_has_callback(true); |
| 577 | 578 |
| 578 scoped_ptr<base::DictionaryValue> duplicate_result(utils::ToDictionary( | 579 scoped_ptr<base::DictionaryValue> duplicate_result(utils::ToDictionary( |
| 579 utils::RunFunctionAndReturnSingleResult( | 580 utils::RunFunctionAndReturnSingleResult( |
| 580 duplicate_tab_function.get(), base::StringPrintf("[%u]", tab_id), | 581 duplicate_tab_function.get(), base::StringPrintf("[%u]", tab_id), |
| 581 browser()))); | 582 browser()))); |
| 582 | 583 |
| 583 int duplicate_tab_id = utils::GetInteger(duplicate_result.get(), "id"); | 584 int duplicate_tab_id = utils::GetInteger(duplicate_result.get(), "id"); |
| 584 int duplicate_tab_window_id = utils::GetInteger(duplicate_result.get(), | 585 int duplicate_tab_window_id = utils::GetInteger(duplicate_result.get(), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 const char* scope); | 624 const char* scope); |
| 624 | 625 |
| 625 content::WebContents* OpenUrlAndWaitForLoad(const GURL& url); | 626 content::WebContents* OpenUrlAndWaitForLoad(const GURL& url); |
| 626 | 627 |
| 627 private: | 628 private: |
| 628 scoped_refptr<Extension> extension_; | 629 scoped_refptr<Extension> extension_; |
| 629 }; | 630 }; |
| 630 | 631 |
| 631 void ExtensionTabsZoomTest::SetUpOnMainThread() { | 632 void ExtensionTabsZoomTest::SetUpOnMainThread() { |
| 632 ExtensionTabsTest::SetUpOnMainThread(); | 633 ExtensionTabsTest::SetUpOnMainThread(); |
| 633 extension_ = utils::CreateEmptyExtension(); | 634 extension_ = test_util::CreateEmptyExtension(); |
| 634 } | 635 } |
| 635 | 636 |
| 636 bool ExtensionTabsZoomTest::RunSetZoom(int tab_id, double zoom_factor) { | 637 bool ExtensionTabsZoomTest::RunSetZoom(int tab_id, double zoom_factor) { |
| 637 scoped_refptr<TabsSetZoomFunction> set_zoom_function( | 638 scoped_refptr<TabsSetZoomFunction> set_zoom_function( |
| 638 new TabsSetZoomFunction()); | 639 new TabsSetZoomFunction()); |
| 639 set_zoom_function->set_extension(extension_.get()); | 640 set_zoom_function->set_extension(extension_.get()); |
| 640 set_zoom_function->set_has_callback(true); | 641 set_zoom_function->set_has_callback(true); |
| 641 | 642 |
| 642 return utils::RunFunction( | 643 return utils::RunFunction( |
| 643 set_zoom_function.get(), | 644 set_zoom_function.get(), |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 // Test chrome.tabs.setZoom(). | 905 // Test chrome.tabs.setZoom(). |
| 905 error = RunSetZoomExpectError(tab_id, 3.14159); | 906 error = RunSetZoomExpectError(tab_id, 3.14159); |
| 906 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); | 907 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); |
| 907 | 908 |
| 908 // chrome.tabs.setZoomSettings(). | 909 // chrome.tabs.setZoomSettings(). |
| 909 error = RunSetZoomSettingsExpectError(tab_id, "manual", "per-tab"); | 910 error = RunSetZoomSettingsExpectError(tab_id, "manual", "per-tab"); |
| 910 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); | 911 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); |
| 911 } | 912 } |
| 912 | 913 |
| 913 } // namespace extensions | 914 } // namespace extensions |
| OLD | NEW |