OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/managed_mode/managed_mode.h" | 5 #include "chrome/browser/managed_mode/managed_mode.h" |
6 #include "chrome/browser/extensions/extension_apitest.h" | 6 #include "chrome/browser/extensions/extension_apitest.h" |
7 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
8 #include "chrome/common/chrome_switches.h" | 8 #include "chrome/common/chrome_switches.h" |
9 #include "chrome/common/extensions/extension.h" | 9 #include "chrome/common/extensions/extension.h" |
10 #include "chrome/test/base/ui_test_utils.h" | 10 #include "chrome/test/base/ui_test_utils.h" |
11 | 11 |
12 // Tests enabling and querying managed mode. | 12 // Tests enabling and querying managed mode. |
13 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ManagedModeGetAndEnable) { | 13 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ManagedModeGetAndEnable) { |
14 ASSERT_FALSE(ManagedMode::IsInManagedMode()); | 14 ASSERT_FALSE(ManagedMode::IsInManagedMode()); |
15 | 15 |
16 ASSERT_TRUE(RunComponentExtensionTest("managed_mode/get_enter")) << message_; | 16 ASSERT_TRUE(RunComponentExtensionTest("managed_mode/get_enter")) << message_; |
17 | 17 |
18 EXPECT_TRUE(ManagedMode::IsInManagedMode()); | 18 EXPECT_TRUE(ManagedMode::IsInManagedMode()); |
19 } | 19 } |
20 | 20 |
21 // Tests the event when entering or leaving managed mode. | 21 // Tests the event when entering or leaving managed mode. |
22 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ManagedModeOnChange) { | 22 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ManagedModeOnChange) { |
23 ASSERT_FALSE(ManagedMode::IsInManagedMode()); | 23 ASSERT_FALSE(ManagedMode::IsInManagedMode()); |
24 | 24 |
25 // We can't just call RunComponentExtension() like above, because we need to | 25 // We can't just call RunComponentExtension() like above, because we need to |
26 // fire the event while the page is waiting. | 26 // fire the event while the page is waiting. |
27 FilePath extension_path = | 27 base::FilePath extension_path = |
28 test_data_dir_.AppendASCII("managed_mode/on_change"); | 28 test_data_dir_.AppendASCII("managed_mode/on_change"); |
29 const extensions::Extension* extension = | 29 const extensions::Extension* extension = |
30 LoadExtensionAsComponent(extension_path); | 30 LoadExtensionAsComponent(extension_path); |
31 ASSERT_TRUE(extension) << "Failed to load extension."; | 31 ASSERT_TRUE(extension) << "Failed to load extension."; |
32 | 32 |
33 ResultCatcher catcher; | 33 ResultCatcher catcher; |
34 // Tell the test what values for the |onChange| event to expect. | 34 // Tell the test what values for the |onChange| event to expect. |
35 std::string page_url = "test.html?expect=true,false"; | 35 std::string page_url = "test.html?expect=true,false"; |
36 ui_test_utils::NavigateToURL(browser(), | 36 ui_test_utils::NavigateToURL(browser(), |
37 extension->GetResourceURL(page_url)); | 37 extension->GetResourceURL(page_url)); |
38 | 38 |
39 // Fire the extension event when entering managed mode. We directly call | 39 // Fire the extension event when entering managed mode. We directly call |
40 // SetInManagedMode() to bypass any confirmation dialogs etc. | 40 // SetInManagedMode() to bypass any confirmation dialogs etc. |
41 ManagedMode::GetInstance()->SetInManagedMode(browser()->profile()); | 41 ManagedMode::GetInstance()->SetInManagedMode(browser()->profile()); |
42 | 42 |
43 // Fire the extension event when leaving managed mode. | 43 // Fire the extension event when leaving managed mode. |
44 ManagedMode::GetInstance()->SetInManagedMode(NULL); | 44 ManagedMode::GetInstance()->SetInManagedMode(NULL); |
45 | 45 |
46 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 46 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
47 } | 47 } |
OLD | NEW |