Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / system_indicator / system_indicator_apitest.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/extensions/api/system_indicator/system_indicator_manager.h"
6 #include "chrome/browser/extensions/api/system_indicator/system_indicator_manager_factory.h"
7 #include "chrome/browser/extensions/extension_action.h"
8 #include "chrome/browser/extensions/extension_action_manager.h"
9 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/browser/extensions/lazy_background_page_test_util.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "extensions/browser/process_manager.h"
13 #include "extensions/common/extension.h"
14 #include "extensions/test/result_catcher.h"
15
16 class SystemIndicatorApiTest : public ExtensionApiTest {
17  public:
18   void SetUpOnMainThread() override {
19     ExtensionApiTest::SetUpOnMainThread();
20     // Set shorter delays to prevent test timeouts in tests that need to wait
21     // for the event page to unload.
22     extensions::ProcessManager::SetEventPageIdleTimeForTesting(1);
23     extensions::ProcessManager::SetEventPageSuspendingTimeForTesting(1);
24   }
25
26   const extensions::Extension* LoadExtensionAndWait(
27       const std::string& test_name) {
28     LazyBackgroundObserver page_complete;
29     base::FilePath extdir = test_data_dir_.AppendASCII(test_name);
30     const extensions::Extension* extension = LoadExtension(extdir);
31     if (extension)
32       page_complete.Wait();
33     return extension;
34   }
35 };
36
37 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, SystemIndicator) {
38   // Only run this test on supported platforms.  SystemIndicatorManagerFactory
39   // returns NULL on unsupported platforms.
40   extensions::SystemIndicatorManager* manager =
41       extensions::SystemIndicatorManagerFactory::GetForProfile(profile());
42   if (manager) {
43     ASSERT_TRUE(RunExtensionTest("system_indicator/basics")) << message_;
44   }
45 }
46
47 IN_PROC_BROWSER_TEST_F(SystemIndicatorApiTest, SystemIndicator) {
48   // Only run this test on supported platforms.  SystemIndicatorManagerFactory
49   // returns NULL on unsupported platforms.
50   extensions::SystemIndicatorManager* manager =
51       extensions::SystemIndicatorManagerFactory::GetForProfile(profile());
52   if (manager) {
53     extensions::ResultCatcher catcher;
54
55     const extensions::Extension* extension =
56         LoadExtensionAndWait("system_indicator/unloaded");
57     ASSERT_TRUE(extension) << message_;
58
59     // Lazy Background Page has been shut down.
60     extensions::ProcessManager* pm = extensions::ProcessManager::Get(profile());
61     EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id()));
62
63     EXPECT_TRUE(manager->SendClickEventToExtensionForTest(extension->id()));
64     EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
65   }
66 }