| 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 #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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateNoPermissions) { | 256 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateNoPermissions) { |
| 257 // The test empty extension has no permissions, therefore it should not get | 257 // The test empty extension has no permissions, therefore it should not get |
| 258 // tab data in the function result. | 258 // tab data in the function result. |
| 259 scoped_refptr<UpdateTabFunction> update_tab_function(new UpdateTabFunction()); | 259 scoped_refptr<UpdateTabFunction> update_tab_function(new UpdateTabFunction()); |
| 260 scoped_refptr<extensions::Extension> empty_extension( | 260 scoped_refptr<extensions::Extension> empty_extension( |
| 261 utils::CreateEmptyExtension()); | 261 utils::CreateEmptyExtension()); |
| 262 update_tab_function->set_extension(empty_extension.get()); | 262 update_tab_function->set_extension(empty_extension.get()); |
| 263 // Without a callback the function will not generate a result. | 263 // Without a callback the function will not generate a result. |
| 264 update_tab_function->set_has_callback(true); | 264 update_tab_function->set_has_callback(true); |
| 265 | 265 |
| 266 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( | 266 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( |
| 267 utils::RunFunctionAndReturnSingleResult( |
| 267 update_tab_function.get(), | 268 update_tab_function.get(), |
| 268 "[null, {\"url\": \"neutrinos\"}]", | 269 "[null, {\"url\": \"about:blank\", \"pinned\": true}]", |
| 269 browser())); | 270 browser()))); |
| 270 EXPECT_EQ(base::Value::TYPE_NULL, result->GetType()); | 271 // The url is stripped since the extension does not have tab permissions. |
| 272 EXPECT_FALSE(result->HasKey("url")); |
| 273 EXPECT_TRUE(utils::GetBoolean(result.get(), "pinned")); |
| 271 } | 274 } |
| 272 | 275 |
| 273 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, | 276 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, |
| 274 DefaultToIncognitoWhenItIsForced) { | 277 DefaultToIncognitoWhenItIsForced) { |
| 275 static const char kArgsWithoutExplicitIncognitoParam[] = | 278 static const char kArgsWithoutExplicitIncognitoParam[] = |
| 276 "[{\"url\": \"about:blank\"}]"; | 279 "[{\"url\": \"about:blank\"}]"; |
| 277 // Force Incognito mode. | 280 // Force Incognito mode. |
| 278 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), | 281 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), |
| 279 IncognitoModePrefs::FORCED); | 282 IncognitoModePrefs::FORCED); |
| 280 // Run without an explicit "incognito" param. | 283 // Run without an explicit "incognito" param. |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 const size_t kExtraWindows = 3; | 405 const size_t kExtraWindows = 3; |
| 403 for (size_t i = 0; i < kExtraWindows; ++i) | 406 for (size_t i = 0; i < kExtraWindows; ++i) |
| 404 CreateBrowser(browser()->profile()); | 407 CreateBrowser(browser()->profile()); |
| 405 | 408 |
| 406 GURL url; | 409 GURL url; |
| 407 AddTabAtIndexToBrowser(browser(), 0, url, content::PAGE_TRANSITION_LINK); | 410 AddTabAtIndexToBrowser(browser(), 0, url, content::PAGE_TRANSITION_LINK); |
| 408 int window_id = ExtensionTabUtil::GetWindowId(browser()); | 411 int window_id = ExtensionTabUtil::GetWindowId(browser()); |
| 409 | 412 |
| 410 // Get tabs in the 'current' window called from non-focused browser. | 413 // Get tabs in the 'current' window called from non-focused browser. |
| 411 scoped_refptr<QueryTabsFunction> function = new QueryTabsFunction(); | 414 scoped_refptr<QueryTabsFunction> function = new QueryTabsFunction(); |
| 415 function->set_extension(utils::CreateEmptyExtension().get()); |
| 412 scoped_ptr<base::ListValue> result(utils::ToList( | 416 scoped_ptr<base::ListValue> result(utils::ToList( |
| 413 utils::RunFunctionAndReturnSingleResult(function.get(), | 417 utils::RunFunctionAndReturnSingleResult(function.get(), |
| 414 "[{\"currentWindow\":true}]", | 418 "[{\"currentWindow\":true}]", |
| 415 browser()))); | 419 browser()))); |
| 416 | 420 |
| 417 ListValue* result_tabs = result.get(); | 421 ListValue* result_tabs = result.get(); |
| 418 // We should have one initial tab and one added tab. | 422 // We should have one initial tab and one added tab. |
| 419 EXPECT_EQ(2u, result_tabs->GetSize()); | 423 EXPECT_EQ(2u, result_tabs->GetSize()); |
| 420 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { | 424 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { |
| 421 DictionaryValue* result_tab = NULL; | 425 DictionaryValue* result_tab = NULL; |
| 422 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); | 426 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); |
| 423 EXPECT_EQ(window_id, utils::GetInteger(result_tab, keys::kWindowIdKey)); | 427 EXPECT_EQ(window_id, utils::GetInteger(result_tab, keys::kWindowIdKey)); |
| 424 } | 428 } |
| 425 | 429 |
| 426 // Get tabs NOT in the 'current' window called from non-focused browser. | 430 // Get tabs NOT in the 'current' window called from non-focused browser. |
| 427 function = new QueryTabsFunction(); | 431 function = new QueryTabsFunction(); |
| 432 function->set_extension(utils::CreateEmptyExtension().get()); |
| 428 result.reset(utils::ToList( | 433 result.reset(utils::ToList( |
| 429 utils::RunFunctionAndReturnSingleResult(function.get(), | 434 utils::RunFunctionAndReturnSingleResult(function.get(), |
| 430 "[{\"currentWindow\":false}]", | 435 "[{\"currentWindow\":false}]", |
| 431 browser()))); | 436 browser()))); |
| 432 | 437 |
| 433 result_tabs = result.get(); | 438 result_tabs = result.get(); |
| 434 // We should have one tab for each extra window. | 439 // We should have one tab for each extra window. |
| 435 EXPECT_EQ(kExtraWindows, result_tabs->GetSize()); | 440 EXPECT_EQ(kExtraWindows, result_tabs->GetSize()); |
| 436 for (size_t i = 0; i < kExtraWindows; ++i) { | 441 for (size_t i = 0; i < kExtraWindows; ++i) { |
| 437 DictionaryValue* result_tab = NULL; | 442 DictionaryValue* result_tab = NULL; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DontCreateTabInClosingPopupWindow) { | 504 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DontCreateTabInClosingPopupWindow) { |
| 500 // Test creates new popup window, closes it right away and then tries to open | 505 // Test creates new popup window, closes it right away and then tries to open |
| 501 // a new tab in it. Tab should not be opened in the popup window, but in a | 506 // a new tab in it. Tab should not be opened in the popup window, but in a |
| 502 // tabbed browser window. | 507 // tabbed browser window. |
| 503 Browser* popup_browser = new Browser( | 508 Browser* popup_browser = new Browser( |
| 504 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile())); | 509 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile())); |
| 505 int window_id = ExtensionTabUtil::GetWindowId(popup_browser); | 510 int window_id = ExtensionTabUtil::GetWindowId(popup_browser); |
| 506 chrome::CloseWindow(popup_browser); | 511 chrome::CloseWindow(popup_browser); |
| 507 | 512 |
| 508 scoped_refptr<CreateTabFunction> create_tab_function(new CreateTabFunction()); | 513 scoped_refptr<CreateTabFunction> create_tab_function(new CreateTabFunction()); |
| 514 create_tab_function->set_extension(utils::CreateEmptyExtension().get()); |
| 509 // Without a callback the function will not generate a result. | 515 // Without a callback the function will not generate a result. |
| 510 create_tab_function->set_has_callback(true); | 516 create_tab_function->set_has_callback(true); |
| 511 | 517 |
| 512 static const char kNewBlankTabArgs[] = | 518 static const char kNewBlankTabArgs[] = |
| 513 "[{\"url\": \"about:blank\", \"windowId\": %u}]"; | 519 "[{\"url\": \"about:blank\", \"windowId\": %u}]"; |
| 514 | 520 |
| 515 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( | 521 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( |
| 516 utils::RunFunctionAndReturnSingleResult( | 522 utils::RunFunctionAndReturnSingleResult( |
| 517 create_tab_function.get(), | 523 create_tab_function.get(), |
| 518 base::StringPrintf(kNewBlankTabArgs, window_id), | 524 base::StringPrintf(kNewBlankTabArgs, window_id), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 static const char kArgsMaximizedWithBounds[] = | 563 static const char kArgsMaximizedWithBounds[] = |
| 558 "[%u, {\"state\": \"maximized\", \"width\": 500}]"; | 564 "[%u, {\"state\": \"maximized\", \"width\": 500}]"; |
| 559 function = new UpdateWindowFunction(); | 565 function = new UpdateWindowFunction(); |
| 560 EXPECT_TRUE(MatchPattern( | 566 EXPECT_TRUE(MatchPattern( |
| 561 utils::RunFunctionAndReturnError( | 567 utils::RunFunctionAndReturnError( |
| 562 function.get(), | 568 function.get(), |
| 563 base::StringPrintf(kArgsMaximizedWithBounds, window_id), | 569 base::StringPrintf(kArgsMaximizedWithBounds, window_id), |
| 564 browser()), | 570 browser()), |
| 565 keys::kInvalidWindowStateError)); | 571 keys::kInvalidWindowStateError)); |
| 566 } | 572 } |
| OLD | NEW |