processes_apitest.cc revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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 "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/task_manager/task_manager_browsertest_util.h"
10#include "chrome/browser/ui/browser.h"
11#include "chrome/browser/ui/browser_dialogs.h"
12#include "chrome/browser/ui/browser_window.h"
13#include "chrome/common/chrome_switches.h"
14
15// Sometimes times out on Mac OS and Windows
16// crbug.com/97499
17// Also on Linux: crbug.com/130138
18#if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX) || defined(OS_CHROMEOS)
19IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_Processes) {
20#else
21IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Processes) {
22#endif
23  CommandLine::ForCurrentProcess()->AppendSwitch(
24      switches::kEnableExperimentalExtensionApis);
25
26  ASSERT_TRUE(RunExtensionTest("processes/api")) << message_;
27}
28
29// http://crbug.com/31663
30// TODO(linux_aura) http://crbug.com/163931
31#if !(defined(OS_WIN) && defined(USE_AURA)) && !(defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA))
32
33IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ProcessesVsTaskManager) {
34  CommandLine::ForCurrentProcess()->AppendSwitch(
35      switches::kEnableExperimentalExtensionApis);
36
37  // Ensure task manager is not yet updating
38  TaskManagerModel* model = TaskManager::GetInstance()->model();
39  EXPECT_EQ(0, model->update_requests_);
40  EXPECT_EQ(TaskManagerModel::IDLE, model->update_state_);
41
42  // Load extension that adds listener in background page
43  ExtensionTestMessageListener listener("ready", false);
44  ASSERT_TRUE(LoadExtension(
45      test_data_dir_.AppendASCII("processes").AppendASCII("onupdated")));
46  ASSERT_TRUE(listener.WaitUntilSatisfied());
47
48  // Ensure the task manager has started updating
49  EXPECT_EQ(1, model->update_requests_);
50  EXPECT_EQ(TaskManagerModel::TASK_PENDING, model->update_state_);
51
52  // Now show the task manager and wait for it to be ready
53  chrome::ShowTaskManager(browser());
54
55  EXPECT_EQ(2, model->update_requests_);
56  EXPECT_EQ(TaskManagerModel::TASK_PENDING, model->update_state_);
57
58  // Unload the extension and check that listener count decreases
59  UnloadExtension(last_loaded_extension_id_);
60  EXPECT_EQ(1, model->update_requests_);
61}
62
63#endif
64