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