Home | History | Annotate | Download | only in task_manager
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/task_manager/task_manager.h"
      6 
      7 #include "base/files/file_path.h"
      8 #include "base/strings/stringprintf.h"
      9 #include "base/strings/utf_string_conversions.h"
     10 #include "chrome/browser/browser_process.h"
     11 #include "chrome/browser/chrome_notification_types.h"
     12 #include "chrome/browser/devtools/devtools_window.h"
     13 #include "chrome/browser/extensions/extension_browsertest.h"
     14 #include "chrome/browser/extensions/extension_service.h"
     15 #include "chrome/browser/extensions/extension_system.h"
     16 #include "chrome/browser/infobars/confirm_infobar_delegate.h"
     17 #include "chrome/browser/infobars/infobar.h"
     18 #include "chrome/browser/infobars/infobar_service.h"
     19 #include "chrome/browser/notifications/desktop_notification_service.h"
     20 #include "chrome/browser/notifications/notification.h"
     21 #include "chrome/browser/notifications/notification_test_util.h"
     22 #include "chrome/browser/notifications/notification_ui_manager.h"
     23 #include "chrome/browser/profiles/profile.h"
     24 #include "chrome/browser/task_manager/resource_provider.h"
     25 #include "chrome/browser/task_manager/task_manager_browsertest_util.h"
     26 #include "chrome/browser/ui/browser.h"
     27 #include "chrome/browser/ui/browser_dialogs.h"
     28 #include "chrome/browser/ui/browser_navigator.h"
     29 #include "chrome/browser/ui/browser_window.h"
     30 #include "chrome/browser/ui/panels/panel.h"
     31 #include "chrome/browser/ui/panels/panel_manager.h"
     32 #include "chrome/browser/ui/tabs/tab_strip_model.h"
     33 #include "chrome/browser/web_applications/web_app.h"
     34 #include "chrome/common/chrome_switches.h"
     35 #include "chrome/test/base/in_process_browser_test.h"
     36 #include "chrome/test/base/ui_test_utils.h"
     37 #include "content/public/browser/notification_service.h"
     38 #include "content/public/common/content_switches.h"
     39 #include "content/public/common/page_transition_types.h"
     40 #include "content/public/test/browser_test_utils.h"
     41 #include "extensions/common/extension.h"
     42 #include "grit/generated_resources.h"
     43 #include "net/dns/mock_host_resolver.h"
     44 #include "net/test/embedded_test_server/embedded_test_server.h"
     45 #include "testing/gtest/include/gtest/gtest.h"
     46 #include "ui/base/l10n/l10n_util.h"
     47 
     48 // http://crbug.com/31663
     49 // TODO(linux_aura) http://crbug.com/163931
     50 #if !(defined(OS_WIN) && defined(USE_AURA)) && !(defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA))
     51 
     52 using content::WebContents;
     53 
     54 // On Linux this is crashing intermittently http://crbug/84719
     55 // In some environments this test fails about 1/6 http://crbug/84850
     56 #if defined(OS_LINUX)
     57 #define MAYBE_KillExtension DISABLED_KillExtension
     58 #else
     59 #define MAYBE_KillExtension KillExtension
     60 #endif
     61 
     62 namespace {
     63 
     64 const base::FilePath::CharType* kTitle1File = FILE_PATH_LITERAL("title1.html");
     65 
     66 }  // namespace
     67 
     68 class TaskManagerNoShowBrowserTest : public ExtensionBrowserTest {
     69  public:
     70   TaskManagerNoShowBrowserTest() {}
     71   virtual ~TaskManagerNoShowBrowserTest() {}
     72 
     73   TaskManagerModel* model() const {
     74     return TaskManager::GetInstance()->model();
     75   }
     76 
     77   void ShowTaskManager() {
     78     EXPECT_EQ(0, model()->ResourceCount());
     79 
     80     // Show the task manager. This populates the model, and helps with debugging
     81     // (you see the task manager).
     82     chrome::ShowTaskManager(browser());
     83 
     84     // New Tab Page.
     85     TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
     86   }
     87 
     88   void Refresh() {
     89     model()->Refresh();
     90   }
     91 
     92   int GetUpdateTimeMs() {
     93     return TaskManagerModel::kUpdateTimeMs;
     94   }
     95 
     96  protected:
     97   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
     98     ExtensionBrowserTest::SetUpCommandLine(command_line);
     99 
    100     // Do not prelaunch the GPU process and disable accelerated compositing
    101     // for these tests as the GPU process will show up in task manager but
    102     // whether it appears before or after the new tab renderer process is not
    103     // well defined.
    104     command_line->AppendSwitch(switches::kDisableGpuProcessPrelaunch);
    105     command_line->AppendSwitch(switches::kDisableAcceleratedCompositing);
    106 
    107     // Do not launch device discovery process.
    108     command_line->AppendSwitch(switches::kDisableDeviceDiscoveryNotifications);
    109   }
    110 
    111  private:
    112   DISALLOW_COPY_AND_ASSIGN(TaskManagerNoShowBrowserTest);
    113 };
    114 
    115 class TaskManagerBrowserTest : public TaskManagerNoShowBrowserTest {
    116  public:
    117   TaskManagerBrowserTest() {}
    118   virtual ~TaskManagerBrowserTest() {}
    119 
    120   virtual void SetUpOnMainThread() OVERRIDE {
    121     TaskManagerNoShowBrowserTest::SetUpOnMainThread();
    122     TaskManagerNoShowBrowserTest::ShowTaskManager();
    123   }
    124 
    125  private:
    126   DISALLOW_COPY_AND_ASSIGN(TaskManagerBrowserTest);
    127 };
    128 
    129 #if defined(OS_MACOSX) || defined(OS_LINUX)
    130 #define MAYBE_ShutdownWhileOpen DISABLED_ShutdownWhileOpen
    131 #else
    132 #define MAYBE_ShutdownWhileOpen ShutdownWhileOpen
    133 #endif
    134 
    135 // Regression test for http://crbug.com/13361
    136 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_ShutdownWhileOpen) {
    137   // Showing task manager handled by SetUp.
    138 }
    139 
    140 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeTabContentsChanges) {
    141   int resource_count = TaskManager::GetInstance()->model()->ResourceCount();
    142   // Open a new tab and make sure we notice that.
    143   GURL url(ui_test_utils::GetTestUrl(base::FilePath(
    144       base::FilePath::kCurrentDirectory), base::FilePath(kTitle1File)));
    145   AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED);
    146   TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
    147 
    148   // Check that the last entry is a tab contents resource whose title starts
    149   // starts with "Tab:".
    150   ASSERT_TRUE(model()->GetResourceWebContents(resource_count) != NULL);
    151   base::string16 prefix = l10n_util::GetStringFUTF16(
    152       IDS_TASK_MANAGER_TAB_PREFIX, base::string16());
    153   ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count), prefix,
    154                          true));
    155 
    156   // Close the tab and verify that we notice.
    157   browser()->tab_strip_model()->CloseWebContentsAt(0,
    158                                                    TabStripModel::CLOSE_NONE);
    159   TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
    160 }
    161 
    162 #if defined(USE_ASH)
    163 // This test fails on Ash because task manager treats view type
    164 // Panels differently for Ash.
    165 #define MAYBE_NoticePanelChanges DISABLED_NoticePanelChanges
    166 #else
    167 #define MAYBE_NoticePanelChanges NoticePanelChanges
    168 #endif
    169 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_NoticePanelChanges) {
    170   ASSERT_TRUE(LoadExtension(
    171       test_data_dir_.AppendASCII("good").AppendASCII("Extensions")
    172                     .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
    173                     .AppendASCII("1.0.0.0")));
    174 
    175   // Browser, the New Tab Page and Extension background page.
    176   TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
    177 
    178   // Open a new panel to an extension url and make sure we notice that.
    179   GURL url(
    180     "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/french_sentence.html");
    181   Panel* panel = PanelManager::GetInstance()->CreatePanel(
    182       web_app::GenerateApplicationNameFromExtensionId(
    183           last_loaded_extension_id()),
    184       browser()->profile(),
    185       url,
    186       gfx::Rect(300, 400),
    187       PanelManager::CREATE_AS_DOCKED);
    188   TaskManagerBrowserTestUtil::WaitForWebResourceChange(3);
    189 
    190   // Check that the fourth entry is a resource with the panel's web contents
    191   // and whose title starts with "Extension:".
    192   ASSERT_EQ(panel->GetWebContents(), model()->GetResourceWebContents(3));
    193   base::string16 prefix = l10n_util::GetStringFUTF16(
    194       IDS_TASK_MANAGER_EXTENSION_PREFIX, base::string16());
    195   ASSERT_TRUE(StartsWith(model()->GetResourceTitle(3), prefix, true));
    196 
    197   // Close the panel and verify that we notice.
    198   panel->Close();
    199   TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
    200 
    201   // Unload extension to avoid crash on Windows.
    202   UnloadExtension(last_loaded_extension_id());
    203   TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
    204 }
    205 
    206 #if defined(USE_ASH) || defined(OS_WIN)
    207 // This test fails on Ash because task manager treats view type
    208 // Panels differently for Ash.
    209 // This test also fails on Windows, win_rel trybot. http://crbug.com/166322
    210 #define MAYBE_KillPanelExtension DISABLED_KillPanelExtension
    211 #else
    212 #define MAYBE_KillPanelExtension KillPanelExtension
    213 #endif
    214 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_KillPanelExtension) {
    215   int resource_count = TaskManager::GetInstance()->model()->ResourceCount();
    216 
    217   ASSERT_TRUE(LoadExtension(
    218       test_data_dir_.AppendASCII("good").AppendASCII("Extensions")
    219                     .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
    220                     .AppendASCII("1.0.0.0")));
    221 
    222   // Browser, the New Tab Page and Extension background page.
    223   TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
    224 
    225   // Open a new panel to an extension url and make sure we notice that.
    226   GURL url(
    227     "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/french_sentence.html");
    228   PanelManager::GetInstance()->CreatePanel(
    229       web_app::GenerateApplicationNameFromExtensionId(
    230           last_loaded_extension_id()),
    231       browser()->profile(),
    232       url,
    233       gfx::Rect(300, 400),
    234       PanelManager::CREATE_AS_DOCKED);
    235   TaskManagerBrowserTestUtil::WaitForWebResourceChange(3);
    236 
    237   // Kill the panel extension process and verify that it disappears from the
    238   // model along with its panel.
    239   ASSERT_TRUE(model()->IsBackgroundResource(resource_count));
    240   TaskManager::GetInstance()->KillProcess(resource_count);
    241   TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
    242 }
    243 
    244 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTabs) {
    245   int resource_count = TaskManager::GetInstance()->model()->ResourceCount();
    246   ASSERT_TRUE(LoadExtension(
    247       test_data_dir_.AppendASCII("good").AppendASCII("Extensions")
    248                     .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
    249                     .AppendASCII("1.0.0.0")));
    250 
    251   // Browser, Extension background page, and the New Tab Page.
    252   TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
    253 
    254   // Open a new tab to an extension URL and make sure we notice that.
    255   GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html");
    256   AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED);
    257   TaskManagerBrowserTestUtil::WaitForWebResourceChange(3);
    258 
    259   // Check that the third entry (background) is an extension resource whose
    260   // title starts with "Extension:".
    261   ASSERT_EQ(task_manager::Resource::EXTENSION, model()->GetResourceType(
    262       resource_count));
    263   ASSERT_TRUE(model()->GetResourceWebContents(resource_count) == NULL);
    264   ASSERT_TRUE(model()->GetResourceExtension(resource_count) != NULL);
    265   base::string16 prefix = l10n_util::GetStringFUTF16(
    266       IDS_TASK_MANAGER_EXTENSION_PREFIX, base::string16());
    267   ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count),
    268                          prefix, true));
    269 
    270   // Check that the fourth entry (page.html) is of type extension and has both
    271   // a tab contents and an extension. The title should start with "Extension:".
    272   ASSERT_EQ(task_manager::Resource::EXTENSION, model()->GetResourceType(
    273       resource_count + 1));
    274   ASSERT_TRUE(model()->GetResourceWebContents(resource_count + 1) != NULL);
    275   ASSERT_TRUE(model()->GetResourceExtension(resource_count + 1) != NULL);
    276   ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count + 1),
    277                          prefix, true));
    278 
    279   // Unload extension to avoid crash on Windows.
    280   UnloadExtension(last_loaded_extension_id());
    281   TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
    282 }
    283 
    284 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabs) {
    285   int resource_count = TaskManager::GetInstance()->model()->ResourceCount();
    286   ASSERT_TRUE(LoadExtension(
    287       test_data_dir_.AppendASCII("packaged_app")));
    288   ExtensionService* service = extensions::ExtensionSystem::Get(
    289       browser()->profile())->extension_service();
    290   const extensions::Extension* extension =
    291       service->GetExtensionById(last_loaded_extension_id(), false);
    292 
    293   // New Tab Page.
    294   TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
    295 
    296   // Open a new tab to the app's launch URL and make sure we notice that.
    297   GURL url(extension->GetResourceURL("main.html"));
    298   AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED);
    299   TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
    300 
    301   // Check that the third entry (main.html) is of type extension and has both
    302   // a tab contents and an extension. The title should start with "App:".
    303   ASSERT_EQ(task_manager::Resource::EXTENSION, model()->GetResourceType(
    304       resource_count));
    305   ASSERT_TRUE(model()->GetResourceWebContents(resource_count) != NULL);
    306   ASSERT_TRUE(model()->GetResourceExtension(resource_count) == extension);
    307   base::string16 prefix = l10n_util::GetStringFUTF16(
    308       IDS_TASK_MANAGER_APP_PREFIX, base::string16());
    309   ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count),
    310                          prefix, true));
    311 
    312   // Unload extension to avoid crash on Windows.
    313   UnloadExtension(last_loaded_extension_id());
    314   TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
    315 }
    316 
    317 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabs) {
    318   int resource_count = TaskManager::GetInstance()->model()->ResourceCount();
    319 
    320   // The app under test acts on URLs whose host is "localhost",
    321   // so the URLs we navigate to must have host "localhost".
    322   host_resolver()->AddRule("*", "127.0.0.1");
    323   ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
    324   GURL::Replacements replace_host;
    325   std::string host_str("localhost");  // must stay in scope with replace_host
    326   replace_host.SetHostStr(host_str);
    327   GURL base_url = embedded_test_server()->GetURL(
    328       "/extensions/api_test/app_process/");
    329   base_url = base_url.ReplaceComponents(replace_host);
    330 
    331   // Open a new tab to an app URL before the app is loaded.
    332   GURL url(base_url.Resolve("path1/empty.html"));
    333   content::WindowedNotificationObserver observer(
    334       content::NOTIFICATION_NAV_ENTRY_COMMITTED,
    335       content::NotificationService::AllSources());
    336   AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED);
    337   observer.Wait();
    338 
    339   // Force the TaskManager to query the title.
    340   Refresh();
    341 
    342   // Check that the third entry's title starts with "Tab:".
    343   base::string16 tab_prefix = l10n_util::GetStringFUTF16(
    344       IDS_TASK_MANAGER_TAB_PREFIX, base::string16());
    345   ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count),
    346                          tab_prefix, true));
    347 
    348   // Load the hosted app and make sure it still starts with "Tab:",
    349   // since it hasn't changed to an app process yet.
    350   ASSERT_TRUE(LoadExtension(
    351       test_data_dir_.AppendASCII("api_test").AppendASCII("app_process")));
    352   // Force the TaskManager to query the title.
    353   Refresh();
    354   ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count),
    355                          tab_prefix, true));
    356 
    357   // Now reload and check that the last entry's title now starts with "App:".
    358   ui_test_utils::NavigateToURL(browser(), url);
    359   // Force the TaskManager to query the title.
    360   Refresh();
    361   base::string16 app_prefix = l10n_util::GetStringFUTF16(
    362       IDS_TASK_MANAGER_APP_PREFIX, base::string16());
    363   ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count),
    364                          app_prefix, true));
    365 
    366   // Disable extension and reload page.
    367   DisableExtension(last_loaded_extension_id());
    368   ui_test_utils::NavigateToURL(browser(), url);
    369 
    370   // Force the TaskManager to query the title.
    371   Refresh();
    372 
    373   // The third entry's title should be back to a normal tab.
    374   ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count),
    375                          tab_prefix, true));
    376 }
    377 
    378 // Disabled, http://crbug.com/66957.
    379 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest,
    380                        DISABLED_KillExtensionAndReload) {
    381   ASSERT_TRUE(LoadExtension(
    382       test_data_dir_.AppendASCII("common").AppendASCII("background_page")));
    383 
    384   // Wait until we see the loaded extension in the task manager (the three
    385   // resources are: the browser process, New Tab Page, and the extension).
    386   TaskManagerBrowserTestUtil::WaitForWebResourceChange(3);
    387 
    388   EXPECT_TRUE(model()->GetResourceExtension(0) == NULL);
    389   EXPECT_TRUE(model()->GetResourceExtension(1) == NULL);
    390   ASSERT_TRUE(model()->GetResourceExtension(2) != NULL);
    391 
    392   // Kill the extension process and make sure we notice it.
    393   TaskManager::GetInstance()->KillProcess(2);
    394   TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
    395 
    396   // Reload the extension using the "crashed extension" infobar while the task
    397   // manager is still visible. Make sure we don't crash and the extension
    398   // gets reloaded and noticed in the task manager.
    399   InfoBarService* infobar_service = InfoBarService::FromWebContents(
    400       browser()->tab_strip_model()->GetActiveWebContents());
    401   ASSERT_EQ(1U, infobar_service->infobar_count());
    402   ConfirmInfoBarDelegate* delegate =
    403       infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
    404   ASSERT_TRUE(delegate);
    405   delegate->Accept();
    406   TaskManagerBrowserTestUtil::WaitForWebResourceChange(3);
    407 }
    408 
    409 #if defined(OS_WIN)
    410 // http://crbug.com/93158.
    411 #define MAYBE_ReloadExtension DISABLED_ReloadExtension
    412 #else
    413 #define MAYBE_ReloadExtension ReloadExtension
    414 #endif
    415 
    416 // Regression test for http://crbug.com/18693.
    417 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_ReloadExtension) {
    418   int resource_count = TaskManager::GetInstance()->model()->ResourceCount();
    419   LOG(INFO) << "loading extension";
    420   ASSERT_TRUE(LoadExtension(
    421       test_data_dir_.AppendASCII("common").AppendASCII("background_page")));
    422 
    423   // Wait until we see the loaded extension in the task manager (the three
    424   // resources are: the browser process, New Tab Page, and the extension).
    425   LOG(INFO) << "waiting for resource change";
    426   TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
    427 
    428   EXPECT_TRUE(model()->GetResourceExtension(0) == NULL);
    429   EXPECT_TRUE(model()->GetResourceExtension(1) == NULL);
    430   ASSERT_TRUE(model()->GetResourceExtension(resource_count) != NULL);
    431 
    432   const extensions::Extension* extension = model()->GetResourceExtension(
    433       resource_count);
    434   ASSERT_TRUE(extension != NULL);
    435 
    436   // Reload the extension a few times and make sure our resource count
    437   // doesn't increase.
    438   LOG(INFO) << "First extension reload";
    439   ReloadExtension(extension->id());
    440   TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
    441   extension = model()->GetResourceExtension(resource_count);
    442   ASSERT_TRUE(extension != NULL);
    443 
    444   LOG(INFO) << "Second extension reload";
    445   ReloadExtension(extension->id());
    446   TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
    447   extension = model()->GetResourceExtension(resource_count);
    448   ASSERT_TRUE(extension != NULL);
    449 
    450   LOG(INFO) << "Third extension reload";
    451   ReloadExtension(extension->id());
    452   TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
    453 }
    454 
    455 // Crashy, http://crbug.com/42301.
    456 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest,
    457                        DISABLED_PopulateWebCacheFields) {
    458   int resource_count = TaskManager::GetInstance()->model()->ResourceCount();
    459 
    460   // Open a new tab and make sure we notice that.
    461   GURL url(ui_test_utils::GetTestUrl(base::FilePath(
    462       base::FilePath::kCurrentDirectory), base::FilePath(kTitle1File)));
    463   AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED);
    464   TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
    465 
    466   // Check that we get some value for the cache columns.
    467   DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(resource_count),
    468             l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT));
    469   DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(resource_count),
    470             l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT));
    471   DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(resource_count),
    472             l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT));
    473 }
    474 
    475 // Checks that task manager counts a worker thread JS heap size.
    476 // http://crbug.com/241066
    477 // Flaky, http://crbug.com/259368
    478 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DISABLED_WebWorkerJSHeapMemory) {
    479   GURL url(ui_test_utils::GetTestUrl(base::FilePath(
    480       base::FilePath::kCurrentDirectory), base::FilePath(kTitle1File)));
    481   ui_test_utils::NavigateToURL(browser(), url);
    482   const int extra_timeout_ms = 500;
    483   size_t minimal_heap_size = 2 * 1024 * 1024 * sizeof(void*);
    484   std::string test_js = base::StringPrintf(
    485       "var blob = new Blob([\n"
    486       "    'mem = new Array(%lu);',\n"
    487       "    'for (var i = 0; i < mem.length; i += 16) mem[i] = i;',\n"
    488       "    'postMessage();']);\n"
    489       "blobURL = window.URL.createObjectURL(blob);\n"
    490       "worker = new Worker(blobURL);\n"
    491       "// Give the task manager few seconds to poll for JS heap sizes.\n"
    492       "worker.onmessage = setTimeout.bind(\n"
    493       "    this,\n"
    494       "    function () { window.domAutomationController.send(true); },\n"
    495       "    %d);\n"
    496       "worker.postMessage();\n",
    497       static_cast<unsigned long>(minimal_heap_size),
    498       GetUpdateTimeMs() + extra_timeout_ms);
    499   bool ok;
    500   ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
    501       browser()->tab_strip_model()->GetActiveWebContents(), test_js, &ok));
    502   ASSERT_TRUE(ok);
    503 
    504   int resource_index = TaskManager::GetInstance()->model()->ResourceCount() - 1;
    505   size_t result;
    506 
    507   ASSERT_TRUE(model()->GetV8Memory(resource_index, &result));
    508   LOG(INFO) << "Got V8 Heap Size " << result << " bytes";
    509   EXPECT_GE(result, minimal_heap_size);
    510 
    511   ASSERT_TRUE(model()->GetV8MemoryUsed(resource_index, &result));
    512   LOG(INFO) << "Got V8 Used Heap Size " << result << " bytes";
    513   EXPECT_GE(result, minimal_heap_size);
    514 }
    515 
    516 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeInTabDevToolsWindow) {
    517   DevToolsWindow* dev_tools = DevToolsWindow::ToggleDevToolsWindow(
    518       model()->GetResourceWebContents(1)->GetRenderViewHost(),
    519       true,
    520       DevToolsToggleAction::Inspect());
    521   // Dock side bottom should be the default.
    522   ASSERT_EQ(DEVTOOLS_DOCK_SIDE_BOTTOM, dev_tools->dock_side());
    523   TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
    524 }
    525 
    526 // This test differs from TaskManagerBrowserTest.NoticeInTabDevToolsWindow in
    527 // the order in which the devtools window and task manager are created.
    528 IN_PROC_BROWSER_TEST_F(TaskManagerNoShowBrowserTest,
    529                        NoticeInTabDevToolsWindow) {
    530   // First create the devtools window.
    531   DevToolsWindow* dev_tools = DevToolsWindow::ToggleDevToolsWindow(
    532       browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(),
    533       true,
    534       DevToolsToggleAction::Inspect());
    535   // Dock side bottom should be the default.
    536   ASSERT_EQ(DEVTOOLS_DOCK_SIDE_BOTTOM, dev_tools->dock_side());
    537   // Make sure that the devtools window is loaded before starting the task
    538   // manager.
    539   content::RunAllPendingInMessageLoop();
    540 
    541   // Now add showing the task manager to the queue, and watch for the right
    542   // number of reources to show up.
    543   base::MessageLoop::current()->PostTask(
    544       FROM_HERE,
    545       base::Bind(&TaskManagerNoShowBrowserTest::ShowTaskManager,
    546                  base::Unretained(this)));
    547   TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
    548 }
    549 
    550 #endif
    551