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