1 // Copyright (c) 2011 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 "base/command_line.h"
6 #include "chrome/browser/extensions/extension_apitest.h"
7 #include "chrome/browser/extensions/extension_test_message_listener.h"
8 #include "chrome/browser/task_manager/task_manager.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_window.h"
11 #include "chrome/common/chrome_switches.h"
12
IN_PROC_BROWSER_TEST_F(ExtensionApiTest,Processes)13 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Processes) {
14 CommandLine::ForCurrentProcess()->AppendSwitch(
15 switches::kEnableExperimentalExtensionApis);
16
17 ASSERT_TRUE(RunExtensionTest("processes/api")) << message_;
18 }
19
IN_PROC_BROWSER_TEST_F(ExtensionApiTest,ProcessesVsTaskManager)20 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ProcessesVsTaskManager) {
21 CommandLine::ForCurrentProcess()->AppendSwitch(
22 switches::kEnableExperimentalExtensionApis);
23
24 // Ensure task manager is not yet updating
25 TaskManagerModel* model = TaskManager::GetInstance()->model();
26 EXPECT_EQ(0, model->update_requests_);
27 EXPECT_EQ(TaskManagerModel::IDLE, model->update_state_);
28
29 // Load extension that adds listener in background page
30 ExtensionTestMessageListener listener("ready", false);
31 ASSERT_TRUE(LoadExtension(
32 test_data_dir_.AppendASCII("processes").AppendASCII("onupdated")));
33 ASSERT_TRUE(listener.WaitUntilSatisfied());
34
35 // Ensure the task manager has started updating
36 EXPECT_EQ(1, model->update_requests_);
37 EXPECT_EQ(TaskManagerModel::TASK_PENDING, model->update_state_);
38
39 // Now show the task manager
40 browser()->window()->ShowTaskManager();
41 EXPECT_EQ(2, model->update_requests_);
42 EXPECT_EQ(TaskManagerModel::TASK_PENDING, model->update_state_);
43
44 // Unload the extension and check that listener count decreases
45 UnloadExtension(last_loaded_extension_id_);
46 EXPECT_EQ(1, model->update_requests_);
47 }
48
49