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

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

Issue 2898033002: [TabManager] Move TabManager into chrome/browser/resource_coordinator. (Closed)
Patch Set: rebase Created 3 years, 6 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 <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>
11 11
12 #include "apps/test/app_window_waiter.h" 12 #include "apps/test/app_window_waiter.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/strings/pattern.h" 15 #include "base/strings/pattern.h"
16 #include "base/strings/string_split.h" 16 #include "base/strings/string_split.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "build/build_config.h" 20 #include "build/build_config.h"
21 #include "chrome/browser/apps/app_browsertest_util.h" 21 #include "chrome/browser/apps/app_browsertest_util.h"
22 #include "chrome/browser/browser_process.h" 22 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/devtools/devtools_window_testing.h" 23 #include "chrome/browser/devtools/devtools_window_testing.h"
24 #include "chrome/browser/extensions/api/tabs/tabs_api.h" 24 #include "chrome/browser/extensions/api/tabs/tabs_api.h"
25 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" 25 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
26 #include "chrome/browser/extensions/extension_apitest.h" 26 #include "chrome/browser/extensions/extension_apitest.h"
27 #include "chrome/browser/extensions/extension_function_test_utils.h" 27 #include "chrome/browser/extensions/extension_function_test_utils.h"
28 #include "chrome/browser/extensions/extension_tab_util.h" 28 #include "chrome/browser/extensions/extension_tab_util.h"
29 #include "chrome/browser/extensions/window_controller.h" 29 #include "chrome/browser/extensions/window_controller.h"
30 #include "chrome/browser/memory/tab_manager.h"
31 #include "chrome/browser/prefs/incognito_mode_prefs.h" 30 #include "chrome/browser/prefs/incognito_mode_prefs.h"
32 #include "chrome/browser/profiles/profile.h" 31 #include "chrome/browser/profiles/profile.h"
32 #include "chrome/browser/resource_coordinator/tab_manager.h"
33 #include "chrome/browser/ui/browser.h" 33 #include "chrome/browser/ui/browser.h"
34 #include "chrome/browser/ui/browser_commands.h" 34 #include "chrome/browser/ui/browser_commands.h"
35 #include "chrome/browser/ui/browser_window.h" 35 #include "chrome/browser/ui/browser_window.h"
36 #include "chrome/browser/ui/tabs/tab_strip_model.h" 36 #include "chrome/browser/ui/tabs/tab_strip_model.h"
37 #include "chrome/browser/ui/views/frame/browser_view.h" 37 #include "chrome/browser/ui/views/frame/browser_view.h"
38 #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" 38 #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
39 #include "chrome/test/base/ui_test_utils.h" 39 #include "chrome/test/base/ui_test_utils.h"
40 #include "components/prefs/pref_service.h" 40 #include "components/prefs/pref_service.h"
41 #include "content/public/browser/browser_context.h" 41 #include "content/public/browser/browser_context.h"
42 #include "content/public/browser/notification_service.h" 42 #include "content/public/browser/notification_service.h"
(...skipping 1267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 api::windows::WINDOW_ID_CURRENT), 1310 api::windows::WINDOW_ID_CURRENT),
1311 DevToolsWindowTesting::Get(devtools)->browser()), 1311 DevToolsWindowTesting::Get(devtools)->browser()),
1312 manifest_errors::kCannotAccessPageWithUrl)); 1312 manifest_errors::kCannotAccessPageWithUrl));
1313 1313
1314 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools); 1314 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
1315 } 1315 }
1316 1316
1317 // TODO(georgesak): change this browsertest to an unittest. 1317 // TODO(georgesak): change this browsertest to an unittest.
1318 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DiscardedProperty) { 1318 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DiscardedProperty) {
1319 ASSERT_TRUE(g_browser_process && g_browser_process->GetTabManager()); 1319 ASSERT_TRUE(g_browser_process && g_browser_process->GetTabManager());
1320 memory::TabManager* tab_manager = g_browser_process->GetTabManager(); 1320 resource_coordinator::TabManager* tab_manager =
1321 g_browser_process->GetTabManager();
1321 1322
1322 // Create two aditional tabs. 1323 // Create two aditional tabs.
1323 content::OpenURLParams params(GURL(url::kAboutBlankURL), content::Referrer(), 1324 content::OpenURLParams params(GURL(url::kAboutBlankURL), content::Referrer(),
1324 WindowOpenDisposition::NEW_BACKGROUND_TAB, 1325 WindowOpenDisposition::NEW_BACKGROUND_TAB,
1325 ui::PAGE_TRANSITION_LINK, false); 1326 ui::PAGE_TRANSITION_LINK, false);
1326 content::WebContents* web_contents_a = browser()->OpenURL(params); 1327 content::WebContents* web_contents_a = browser()->OpenURL(params);
1327 content::WebContents* web_contents_b = browser()->OpenURL(params); 1328 content::WebContents* web_contents_b = browser()->OpenURL(params);
1328 1329
1329 // Set up query function with an extension. 1330 // Set up query function with an extension.
1330 scoped_refptr<const Extension> extension = test_util::CreateEmptyExtension(); 1331 scoped_refptr<const Extension> extension = test_util::CreateEmptyExtension();
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 scoped_refptr<TabsDiscardFunction> discard(new TabsDiscardFunction()); 1453 scoped_refptr<TabsDiscardFunction> discard(new TabsDiscardFunction());
1453 discard->set_extension(extension.get()); 1454 discard->set_extension(extension.get());
1454 1455
1455 // Run function passing the tab id as argument. 1456 // Run function passing the tab id as argument.
1456 int tab_id = ExtensionTabUtil::GetTabId(web_contents); 1457 int tab_id = ExtensionTabUtil::GetTabId(web_contents);
1457 std::unique_ptr<base::DictionaryValue> result( 1458 std::unique_ptr<base::DictionaryValue> result(
1458 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult( 1459 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult(
1459 discard.get(), base::StringPrintf("[%u]", tab_id), browser()))); 1460 discard.get(), base::StringPrintf("[%u]", tab_id), browser())));
1460 1461
1461 // Confirms that TabManager sees the tab as discarded. 1462 // Confirms that TabManager sees the tab as discarded.
1462 memory::TabManager* tab_manager = g_browser_process->GetTabManager(); 1463 resource_coordinator::TabManager* tab_manager =
1464 g_browser_process->GetTabManager();
1463 web_contents = browser()->tab_strip_model()->GetWebContentsAt(1); 1465 web_contents = browser()->tab_strip_model()->GetWebContentsAt(1);
1464 EXPECT_TRUE(tab_manager->IsTabDiscarded(web_contents)); 1466 EXPECT_TRUE(tab_manager->IsTabDiscarded(web_contents));
1465 1467
1466 // Make sure the returned tab is the one discarded and its discarded state is 1468 // Make sure the returned tab is the one discarded and its discarded state is
1467 // correct. 1469 // correct.
1468 tab_id = ExtensionTabUtil::GetTabId(web_contents); 1470 tab_id = ExtensionTabUtil::GetTabId(web_contents);
1469 EXPECT_EQ(tab_id, api_test_utils::GetInteger(result.get(), "id")); 1471 EXPECT_EQ(tab_id, api_test_utils::GetInteger(result.get(), "id"));
1470 EXPECT_TRUE(api_test_utils::GetBoolean(result.get(), "discarded")); 1472 EXPECT_TRUE(api_test_utils::GetBoolean(result.get(), "discarded"));
1471 1473
1472 // Tests chrome.tabs.discard(tabId) with an already discarded tab. It has to 1474 // Tests chrome.tabs.discard(tabId) with an already discarded tab. It has to
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 1521 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1520 content::WebContents* web_contents = 1522 content::WebContents* web_contents =
1521 browser()->tab_strip_model()->GetWebContentsAt(1); 1523 browser()->tab_strip_model()->GetWebContentsAt(1);
1522 1524
1523 // Set up the function with an extension. 1525 // Set up the function with an extension.
1524 scoped_refptr<const Extension> extension = test_util::CreateEmptyExtension(); 1526 scoped_refptr<const Extension> extension = test_util::CreateEmptyExtension();
1525 scoped_refptr<TabsDiscardFunction> discard(new TabsDiscardFunction()); 1527 scoped_refptr<TabsDiscardFunction> discard(new TabsDiscardFunction());
1526 discard->set_extension(extension.get()); 1528 discard->set_extension(extension.get());
1527 1529
1528 // Disable protection time to discard the tab without passing id. 1530 // Disable protection time to discard the tab without passing id.
1529 memory::TabManager* tab_manager = g_browser_process->GetTabManager(); 1531 resource_coordinator::TabManager* tab_manager =
1532 g_browser_process->GetTabManager();
1530 tab_manager->set_minimum_protection_time_for_tests( 1533 tab_manager->set_minimum_protection_time_for_tests(
1531 base::TimeDelta::FromSeconds(0)); 1534 base::TimeDelta::FromSeconds(0));
1532 1535
1533 // Run without passing an id. 1536 // Run without passing an id.
1534 std::unique_ptr<base::DictionaryValue> result(utils::ToDictionary( 1537 std::unique_ptr<base::DictionaryValue> result(utils::ToDictionary(
1535 utils::RunFunctionAndReturnSingleResult(discard.get(), "[]", browser()))); 1538 utils::RunFunctionAndReturnSingleResult(discard.get(), "[]", browser())));
1536 1539
1537 // Confirms that TabManager sees the tab as discarded. 1540 // Confirms that TabManager sees the tab as discarded.
1538 web_contents = browser()->tab_strip_model()->GetWebContentsAt(1); 1541 web_contents = browser()->tab_strip_model()->GetWebContentsAt(1);
1539 EXPECT_TRUE(tab_manager->IsTabDiscarded(web_contents)); 1542 EXPECT_TRUE(tab_manager->IsTabDiscarded(web_contents));
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
2192 EXPECT_TRUE(ExecuteScriptAndExtractString( 2195 EXPECT_TRUE(ExecuteScriptAndExtractString(
2193 new_contents, 2196 new_contents,
2194 "var w = window.open('', 'old-contents');\n" 2197 "var w = window.open('', 'old-contents');\n"
2195 "window.domAutomationController.send(w.location.href);", 2198 "window.domAutomationController.send(w.location.href);",
2196 &location_of_other_window)); 2199 &location_of_other_window));
2197 EXPECT_EQ(old_contents->GetMainFrame()->GetLastCommittedURL().spec(), 2200 EXPECT_EQ(old_contents->GetMainFrame()->GetLastCommittedURL().spec(),
2198 location_of_other_window); 2201 location_of_other_window);
2199 } 2202 }
2200 2203
2201 } // namespace extensions 2204 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698