Chromium Code Reviews| 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 <limits.h> | 5 #include <limits.h> |
| 6 #include <stddef.h> | 6 #include <stddef.h> |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
| 31 #include "chrome/browser/ui/browser.h" | 31 #include "chrome/browser/ui/browser.h" |
| 32 #include "chrome/browser/ui/browser_commands.h" | 32 #include "chrome/browser/ui/browser_commands.h" |
| 33 #include "chrome/browser/ui/browser_window.h" | 33 #include "chrome/browser/ui/browser_window.h" |
| 34 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 34 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 35 #include "chrome/browser/ui/views/frame/browser_view.h" | 35 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 36 #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" | 36 #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" |
| 37 #include "chrome/test/base/ui_test_utils.h" | 37 #include "chrome/test/base/ui_test_utils.h" |
| 38 #include "components/prefs/pref_service.h" | 38 #include "components/prefs/pref_service.h" |
| 39 #include "content/public/browser/browser_context.h" | 39 #include "content/public/browser/browser_context.h" |
| 40 #include "content/public/browser/notification_service.h" | |
| 40 #include "content/public/browser/storage_partition.h" | 41 #include "content/public/browser/storage_partition.h" |
| 41 #include "content/public/common/page_zoom.h" | 42 #include "content/public/common/page_zoom.h" |
| 42 #include "content/public/common/url_constants.h" | 43 #include "content/public/common/url_constants.h" |
| 43 #include "extensions/browser/api_test_utils.h" | 44 #include "extensions/browser/api_test_utils.h" |
| 44 #include "extensions/browser/app_window/app_window.h" | 45 #include "extensions/browser/app_window/app_window.h" |
| 45 #include "extensions/browser/app_window/app_window_registry.h" | 46 #include "extensions/browser/app_window/app_window_registry.h" |
| 46 #include "extensions/browser/app_window/native_app_window.h" | 47 #include "extensions/browser/app_window/native_app_window.h" |
| 47 #include "extensions/common/manifest_constants.h" | 48 #include "extensions/common/manifest_constants.h" |
| 48 #include "extensions/common/test_util.h" | 49 #include "extensions/common/test_util.h" |
| 49 #include "extensions/test/extension_test_message_listener.h" | 50 #include "extensions/test/extension_test_message_listener.h" |
| (...skipping 1382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1432 } | 1433 } |
| 1433 | 1434 |
| 1434 // Get discarded tabs after activating a discarded tab. | 1435 // Get discarded tabs after activating a discarded tab. |
| 1435 { | 1436 { |
| 1436 std::unique_ptr<base::ListValue> result( | 1437 std::unique_ptr<base::ListValue> result( |
| 1437 RunQueryFunction("[{\"discarded\": true}]")); | 1438 RunQueryFunction("[{\"discarded\": true}]")); |
| 1438 EXPECT_EQ(1u, result->GetSize()); | 1439 EXPECT_EQ(1u, result->GetSize()); |
| 1439 } | 1440 } |
| 1440 } | 1441 } |
| 1441 | 1442 |
| 1443 // Tests chrome.tabs.discard(tabId). | |
| 1444 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DiscardWithId) { | |
| 1445 // Create an aditional tab. | |
| 1446 content::OpenURLParams params(GURL(url::kAboutBlankURL), content::Referrer(), | |
| 1447 NEW_BACKGROUND_TAB, ui::PAGE_TRANSITION_LINK, | |
| 1448 false); | |
| 1449 content::WebContents* web_contents = browser()->OpenURL(params); | |
|
Devlin
2016/07/21 15:39:21
We should probably wait for load stop here. ui_te
Anderson Silva
2016/07/21 20:43:04
Done.
Had to use NavigateToURLWithDisposition() in
| |
| 1450 | |
| 1451 // Set up the function with an extension. | |
| 1452 scoped_refptr<const Extension> extension = test_util::CreateEmptyExtension(); | |
| 1453 scoped_refptr<TabsDiscardFunction> discard(new TabsDiscardFunction()); | |
| 1454 discard->set_extension(extension.get()); | |
| 1455 discard->set_has_callback(true); | |
|
Devlin
2016/07/21 15:39:21
Is this necessary?
Anderson Silva
2016/07/21 20:43:04
Not anymore, because we are always returning resul
| |
| 1456 | |
| 1457 // Run function passing the tab id as argument. | |
| 1458 int tab_id = ExtensionTabUtil::GetTabId(web_contents); | |
| 1459 utils::RunFunction(discard.get(), base::StringPrintf("[%u]", tab_id), | |
| 1460 browser(), utils::NONE); | |
| 1461 | |
| 1462 // Make sure the result was successfull. | |
| 1463 const base::Value* result_success; | |
| 1464 discard->GetResultList()->Get(1, &result_success); | |
|
Devlin
2016/07/21 15:39:21
Couldn't we just use ListValue::GetBoolean()?
Anderson Silva
2016/07/21 20:43:04
Yes, we probably could. I didn't see we had that.
| |
| 1465 bool success = false; | |
| 1466 result_success->GetAsBoolean(&success); | |
| 1467 EXPECT_TRUE(success); | |
| 1468 | |
| 1469 // Confirms that TabManager sees the the tab as discarded. | |
|
Devlin
2016/07/21 15:39:21
typo: 'the the'
Anderson Silva
2016/07/21 20:43:04
Done.
| |
| 1470 memory::TabManager* tab_manager = g_browser_process->GetTabManager(); | |
| 1471 ASSERT_TRUE(tab_manager); | |
| 1472 web_contents = browser()->tab_strip_model()->GetWebContentsAt(1); | |
| 1473 EXPECT_TRUE(tab_manager->IsTabDiscarded(web_contents)); | |
| 1474 | |
| 1475 // Make sure the returned tab is the one discarded and | |
| 1476 // its discarded state is correct. | |
| 1477 const base::Value* result_tab; | |
| 1478 discard->GetResultList()->Get(0, &result_tab); | |
|
Devlin
2016/07/21 15:39:21
here, too - why not just GetDictionary?
Anderson Silva
2016/07/21 20:43:04
Done. Same.
| |
| 1479 std::unique_ptr<base::DictionaryValue> result_dict( | |
| 1480 utils::ToDictionary(result_tab->DeepCopy())); | |
| 1481 | |
| 1482 tab_id = ExtensionTabUtil::GetTabId(web_contents); | |
| 1483 EXPECT_EQ(tab_id, api_test_utils::GetInteger(result_dict.get(), "id")); | |
| 1484 EXPECT_TRUE(api_test_utils::GetBoolean(result_dict.get(), "discarded")); | |
| 1485 } | |
| 1486 | |
| 1487 // Tests chrome.tabs.discard(). | |
| 1488 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DiscardWithoutId) { | |
| 1489 // Create an aditional tab. | |
| 1490 content::WindowedNotificationObserver load1( | |
| 1491 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
| 1492 content::NotificationService::AllSources()); | |
| 1493 content::OpenURLParams params(GURL(url::kAboutBlankURL), content::Referrer(), | |
| 1494 NEW_BACKGROUND_TAB, ui::PAGE_TRANSITION_LINK, | |
| 1495 false); | |
| 1496 content::WebContents* web_contents = browser()->OpenURL(params); | |
|
Devlin
2016/07/21 15:39:21
here too, prefer NavigateToURL so that we know the
Anderson Silva
2016/07/21 20:43:04
Done.
| |
| 1497 load1.Wait(); | |
| 1498 | |
| 1499 // Set up the function with an extension. | |
| 1500 scoped_refptr<const Extension> extension = test_util::CreateEmptyExtension(); | |
| 1501 scoped_refptr<TabsDiscardFunction> discard(new TabsDiscardFunction()); | |
| 1502 discard->set_extension(extension.get()); | |
| 1503 discard->set_has_callback(true); | |
| 1504 | |
| 1505 // Disable protection time to discard the tab without passing id. | |
| 1506 memory::TabManager* tab_manager = g_browser_process->GetTabManager(); | |
| 1507 ASSERT_TRUE(tab_manager); | |
| 1508 tab_manager->set_minimum_protection_time_for_tests( | |
| 1509 base::TimeDelta::FromSeconds(0)); | |
| 1510 | |
| 1511 // Run without passing an id. | |
| 1512 utils::RunFunction(discard.get(), "[]", browser(), utils::NONE); | |
| 1513 | |
| 1514 // Make sure the result was successfull. | |
|
Devlin
2016/07/21 15:39:21
s/successfull/successful
Anderson Silva
2016/07/21 20:43:04
Done.
| |
| 1515 const base::Value* result_success; | |
| 1516 discard->GetResultList()->Get(1, &result_success); | |
| 1517 bool success = false; | |
| 1518 result_success->GetAsBoolean(&success); | |
| 1519 EXPECT_TRUE(success); | |
| 1520 | |
| 1521 // Confirms that TabManager sees the tab as discarded. | |
| 1522 web_contents = browser()->tab_strip_model()->GetWebContentsAt(1); | |
| 1523 EXPECT_TRUE(tab_manager->IsTabDiscarded(web_contents)); | |
| 1524 | |
| 1525 // Make sure the returned tab is the one discarded and | |
| 1526 // its discarded state is correct. | |
| 1527 const base::Value* result_tab; | |
| 1528 discard->GetResultList()->Get(0, &result_tab); | |
| 1529 std::unique_ptr<base::DictionaryValue> result_dict( | |
| 1530 utils::ToDictionary(result_tab->DeepCopy())); | |
| 1531 | |
| 1532 EXPECT_EQ(ExtensionTabUtil::GetTabId(web_contents), | |
| 1533 api_test_utils::GetInteger(result_dict.get(), "id")); | |
| 1534 EXPECT_TRUE(api_test_utils::GetBoolean(result_dict.get(), "discarded")); | |
| 1535 } | |
| 1536 | |
| 1442 // Tester class for the tabs.zoom* api functions. | 1537 // Tester class for the tabs.zoom* api functions. |
| 1443 class ExtensionTabsZoomTest : public ExtensionTabsTest { | 1538 class ExtensionTabsZoomTest : public ExtensionTabsTest { |
| 1444 public: | 1539 public: |
| 1445 void SetUpOnMainThread() override; | 1540 void SetUpOnMainThread() override; |
| 1446 | 1541 |
| 1447 // Runs chrome.tabs.setZoom(). | 1542 // Runs chrome.tabs.setZoom(). |
| 1448 bool RunSetZoom(int tab_id, double zoom_factor); | 1543 bool RunSetZoom(int tab_id, double zoom_factor); |
| 1449 | 1544 |
| 1450 // Runs chrome.tabs.getZoom(). | 1545 // Runs chrome.tabs.getZoom(). |
| 1451 testing::AssertionResult RunGetZoom(int tab_id, double* zoom_factor); | 1546 testing::AssertionResult RunGetZoom(int tab_id, double* zoom_factor); |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1865 EXPECT_TRUE( | 1960 EXPECT_TRUE( |
| 1866 base::MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); | 1961 base::MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); |
| 1867 | 1962 |
| 1868 // chrome.tabs.setZoomSettings(). | 1963 // chrome.tabs.setZoomSettings(). |
| 1869 error = RunSetZoomSettingsExpectError(tab_id, "manual", "per-tab"); | 1964 error = RunSetZoomSettingsExpectError(tab_id, "manual", "per-tab"); |
| 1870 EXPECT_TRUE( | 1965 EXPECT_TRUE( |
| 1871 base::MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); | 1966 base::MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); |
| 1872 } | 1967 } |
| 1873 | 1968 |
| 1874 } // namespace extensions | 1969 } // namespace extensions |
| OLD | NEW |