OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/strings/stringprintf.h" | 5 #include "base/strings/stringprintf.h" |
6 #include "chrome/browser/apps/app_browsertest_util.h" | 6 #include "chrome/browser/apps/app_browsertest_util.h" |
7 #include "chrome/test/base/ui_test_utils.h" | 7 #include "chrome/test/base/ui_test_utils.h" |
8 #include "content/public/test/browser_test_utils.h" | 8 #include "content/public/test/browser_test_utils.h" |
9 #include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h " | |
9 #include "extensions/browser/guest_view/guest_view_manager.h" | 10 #include "extensions/browser/guest_view/guest_view_manager.h" |
10 #include "extensions/browser/guest_view/guest_view_manager_factory.h" | 11 #include "extensions/browser/guest_view/guest_view_manager_factory.h" |
12 #include "extensions/browser/guest_view/test_guest_view_manager.h" | |
11 #include "extensions/test/extension_test_message_listener.h" | 13 #include "extensions/test/extension_test_message_listener.h" |
12 | 14 |
13 namespace { | |
14 | |
15 class TestGuestViewManager : public extensions::GuestViewManager { | |
16 public: | |
17 explicit TestGuestViewManager(content::BrowserContext* context) | |
18 : extensions::GuestViewManager(context), web_contents_(NULL) {} | |
19 | |
20 content::WebContents* WaitForGuestCreated() { | |
21 if (web_contents_) | |
22 return web_contents_; | |
23 | |
24 message_loop_runner_ = new content::MessageLoopRunner; | |
25 message_loop_runner_->Run(); | |
26 return web_contents_; | |
27 } | |
28 | |
29 private: | |
30 // GuestViewManager override. | |
31 void AddGuest(int guest_instance_id, | |
32 content::WebContents* guest_web_contents) override { | |
33 extensions::GuestViewManager::AddGuest(guest_instance_id, | |
34 guest_web_contents); | |
35 web_contents_ = guest_web_contents; | |
36 | |
37 if (message_loop_runner_.get()) | |
38 message_loop_runner_->Quit(); | |
39 } | |
40 | |
41 content::WebContents* web_contents_; | |
42 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
43 }; | |
44 | |
45 // Test factory for creating test instances of GuestViewManager. | |
46 class TestGuestViewManagerFactory : public extensions::GuestViewManagerFactory { | |
47 public: | |
48 TestGuestViewManagerFactory() : test_guest_view_manager_(NULL) {} | |
49 | |
50 ~TestGuestViewManagerFactory() override {} | |
51 | |
52 extensions::GuestViewManager* CreateGuestViewManager( | |
53 content::BrowserContext* context) override { | |
54 return GetManager(context); | |
55 } | |
56 | |
57 TestGuestViewManager* GetManager(content::BrowserContext* context) { | |
58 if (!test_guest_view_manager_) { | |
59 test_guest_view_manager_ = new TestGuestViewManager(context); | |
60 } | |
61 return test_guest_view_manager_; | |
62 } | |
63 | |
64 private: | |
65 TestGuestViewManager* test_guest_view_manager_; | |
66 | |
67 DISALLOW_COPY_AND_ASSIGN(TestGuestViewManagerFactory); | |
68 }; | |
69 | |
70 } // namespace | |
71 | |
72 class ExtensionViewTest : public extensions::PlatformAppBrowserTest { | 15 class ExtensionViewTest : public extensions::PlatformAppBrowserTest { |
73 public: | 16 public: |
74 ExtensionViewTest() { | 17 ExtensionViewTest() { |
75 extensions::GuestViewManager::set_factory_for_testing(&factory_); | 18 extensions::GuestViewManager::set_factory_for_testing(&factory_); |
76 } | 19 } |
77 | 20 |
78 TestGuestViewManager* GetGuestViewManager() { | 21 extensions::TestGuestViewManager* GetGuestViewManager() { |
79 return factory_.GetManager(browser()->profile()); | 22 return static_cast<extensions::TestGuestViewManager*>( |
Fady Samuel
2015/04/24 01:31:23
Implement Create a TestGuestViewManager if one doe
Fady Samuel
2015/04/24 04:37:48
Done.
| |
23 extensions::GuestViewManager::FromBrowserContext(browser()->profile())); | |
80 } | 24 } |
81 | 25 |
82 void TestHelper(const std::string& test_name, | 26 void TestHelper(const std::string& test_name, |
83 const std::string& app_location, | 27 const std::string& app_location, |
84 const std::string& app_to_embed) { | 28 const std::string& app_to_embed) { |
85 LoadAndLaunchPlatformApp(app_location.c_str(), "Launched"); | 29 LoadAndLaunchPlatformApp(app_location.c_str(), "Launched"); |
86 | 30 |
87 // Flush any pending events to make sure we start with a clean slate. | 31 // Flush any pending events to make sure we start with a clean slate. |
88 content::RunAllPendingInMessageLoop(); | 32 content::RunAllPendingInMessageLoop(); |
89 | 33 |
(...skipping 14 matching lines...) Expand all Loading... | |
104 return; | 48 return; |
105 } | 49 } |
106 ASSERT_TRUE(done_listener.WaitUntilSatisfied()); | 50 ASSERT_TRUE(done_listener.WaitUntilSatisfied()); |
107 } | 51 } |
108 | 52 |
109 private: | 53 private: |
110 void SetUpCommandLine(base::CommandLine* command_line) override { | 54 void SetUpCommandLine(base::CommandLine* command_line) override { |
111 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); | 55 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); |
112 } | 56 } |
113 | 57 |
114 TestGuestViewManagerFactory factory_; | 58 extensions::TestGuestViewManagerFactory factory_; |
115 }; | 59 }; |
116 | 60 |
117 // Tests that <extensionview> can be created and added to the DOM. | 61 // Tests that <extensionview> can be created and added to the DOM. |
118 IN_PROC_BROWSER_TEST_F(ExtensionViewTest, | 62 IN_PROC_BROWSER_TEST_F(ExtensionViewTest, |
119 TestExtensionViewCreationShouldSucceed) { | 63 TestExtensionViewCreationShouldSucceed) { |
120 const extensions::Extension* skeleton_app = | 64 const extensions::Extension* skeleton_app = |
121 InstallPlatformApp("extension_view/skeleton"); | 65 InstallPlatformApp("extension_view/skeleton"); |
122 TestHelper("testExtensionViewCreationShouldSucceed", "extension_view", | 66 TestHelper("testExtensionViewCreationShouldSucceed", "extension_view", |
123 skeleton_app->id()); | 67 skeleton_app->id()); |
124 } | 68 } |
125 | 69 |
126 // Tests that verify that <extensionview> can navigate to different sources. | 70 // Tests that verify that <extensionview> can navigate to different sources. |
127 IN_PROC_BROWSER_TEST_F(ExtensionViewTest, ShimSrcAttribute) { | 71 IN_PROC_BROWSER_TEST_F(ExtensionViewTest, ShimSrcAttribute) { |
128 ASSERT_TRUE(RunPlatformAppTest( | 72 ASSERT_TRUE(RunPlatformAppTest( |
129 "platform_apps/extension_view/src_attribute")); | 73 "platform_apps/extension_view/src_attribute")); |
130 } | 74 } |
131 | 75 |
132 // Tests that verify that <extensionview> can call the connect function. | 76 // Tests that verify that <extensionview> can call the connect function. |
133 IN_PROC_BROWSER_TEST_F(ExtensionViewTest, ConnectAPICall) { | 77 IN_PROC_BROWSER_TEST_F(ExtensionViewTest, ConnectAPICall) { |
134 ASSERT_TRUE(RunPlatformAppTest("platform_apps/extension_view/connect_api")); | 78 ASSERT_TRUE(RunPlatformAppTest("platform_apps/extension_view/connect_api")); |
135 } | 79 } |
136 | 80 |
137 // Tests that verify that <extensionview> does not change extension ID if | 81 // Tests that verify that <extensionview> does not change extension ID if |
138 // someone tries to change it in JavaScript. | 82 // someone tries to change it in JavaScript. |
139 IN_PROC_BROWSER_TEST_F(ExtensionViewTest, ShimExtensionAttribute) { | 83 IN_PROC_BROWSER_TEST_F(ExtensionViewTest, ShimExtensionAttribute) { |
140 ASSERT_TRUE(RunPlatformAppTest( | 84 ASSERT_TRUE(RunPlatformAppTest( |
141 "platform_apps/extension_view/extension_attribute")); | 85 "platform_apps/extension_view/extension_attribute")); |
142 } | 86 } |
OLD | NEW |