Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: chrome/browser/apps/guest_view/extension_view_browsertest.cc

Issue 873933002: Add <extensionview> (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move test files out of shim/ directory Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/public/browser/notification_service.h" 7 #include "chrome/test/base/ui_test_utils.h"
8 #include "content/public/browser/render_process_host.h"
9 #include "content/public/test/browser_test_utils.h" 8 #include "content/public/test/browser_test_utils.h"
10 #include "content/public/test/test_utils.h"
11 #include "extensions/browser/guest_view/guest_view_manager.h" 9 #include "extensions/browser/guest_view/guest_view_manager.h"
12 #include "extensions/browser/guest_view/guest_view_manager_factory.h" 10 #include "extensions/browser/guest_view/guest_view_manager_factory.h"
13 #include "extensions/common/switches.h"
14 #include "extensions/test/extension_test_message_listener.h" 11 #include "extensions/test/extension_test_message_listener.h"
15 #include "net/test/embedded_test_server/embedded_test_server.h"
16 #include "net/test/embedded_test_server/http_request.h"
17 #include "net/test/embedded_test_server/http_response.h"
18 12
19 namespace { 13 namespace {
20 14
21 class TestGuestViewManager : public extensions::GuestViewManager { 15 class TestGuestViewManager : public extensions::GuestViewManager {
22 public: 16 public:
23 explicit TestGuestViewManager(content::BrowserContext* context) : 17 explicit TestGuestViewManager(content::BrowserContext* context)
24 extensions::GuestViewManager(context), 18 : extensions::GuestViewManager(context), web_contents_(NULL) {}
25 web_contents_(NULL) {}
26 19
27 content::WebContents* WaitForGuestCreated() { 20 content::WebContents* WaitForGuestCreated() {
28 if (web_contents_) 21 if (web_contents_)
29 return web_contents_; 22 return web_contents_;
30 23
31 message_loop_runner_ = new content::MessageLoopRunner; 24 message_loop_runner_ = new content::MessageLoopRunner;
32 message_loop_runner_->Run(); 25 message_loop_runner_->Run();
33 return web_contents_; 26 return web_contents_;
34 } 27 }
35 28
36 private: 29 private:
37 // GuestViewManager override: 30 // GuestViewManager override.
38 void AddGuest(int guest_instance_id, 31 void AddGuest(int guest_instance_id,
39 content::WebContents* guest_web_contents) override { 32 content::WebContents* guest_web_contents) override {
40 extensions::GuestViewManager::AddGuest( 33 extensions::GuestViewManager::AddGuest(guest_instance_id,
41 guest_instance_id, guest_web_contents); 34 guest_web_contents);
42 web_contents_ = guest_web_contents; 35 web_contents_ = guest_web_contents;
43 36
44 if (message_loop_runner_.get()) 37 if (message_loop_runner_.get())
45 message_loop_runner_->Quit(); 38 message_loop_runner_->Quit();
46 } 39 }
47 40
48 content::WebContents* web_contents_; 41 content::WebContents* web_contents_;
49 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 42 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
50 }; 43 };
51 44
52 // Test factory for creating test instances of GuestViewManager. 45 // Test factory for creating test instances of GuestViewManager.
53 class TestGuestViewManagerFactory : public extensions::GuestViewManagerFactory { 46 class TestGuestViewManagerFactory : public extensions::GuestViewManagerFactory {
54 public: 47 public:
55 TestGuestViewManagerFactory() : 48 TestGuestViewManagerFactory() : test_guest_view_manager_(NULL) {}
56 test_guest_view_manager_(NULL) {}
57 49
58 ~TestGuestViewManagerFactory() override {} 50 ~TestGuestViewManagerFactory() override {}
59 51
60 extensions::GuestViewManager* CreateGuestViewManager( 52 extensions::GuestViewManager* CreateGuestViewManager(
61 content::BrowserContext* context) override { 53 content::BrowserContext* context) override {
62 return GetManager(context); 54 return GetManager(context);
63 } 55 }
64 56
65 TestGuestViewManager* GetManager(content::BrowserContext* context) { 57 TestGuestViewManager* GetManager(content::BrowserContext* context) {
66 if (!test_guest_view_manager_) { 58 if (!test_guest_view_manager_) {
67 test_guest_view_manager_ = new TestGuestViewManager(context); 59 test_guest_view_manager_ = new TestGuestViewManager(context);
68 } 60 }
69 return test_guest_view_manager_; 61 return test_guest_view_manager_;
70 } 62 }
71 63
72 private: 64 private:
73 TestGuestViewManager* test_guest_view_manager_; 65 TestGuestViewManager* test_guest_view_manager_;
74 66
75 DISALLOW_COPY_AND_ASSIGN(TestGuestViewManagerFactory); 67 DISALLOW_COPY_AND_ASSIGN(TestGuestViewManagerFactory);
76 }; 68 };
77 69
78 } // namespace 70 } // namespace
79 71
80 class AppViewTest : public extensions::PlatformAppBrowserTest { 72 class ExtensionViewTest : public extensions::PlatformAppBrowserTest {
81 public: 73 public:
82 AppViewTest() { 74 ExtensionViewTest() {
83 extensions::GuestViewManager::set_factory_for_testing(&factory_); 75 extensions::GuestViewManager::set_factory_for_testing(&factory_);
84 } 76 }
85 77
86 TestGuestViewManager* GetGuestViewManager() { 78 TestGuestViewManager* GetGuestViewManager() {
87 return factory_.GetManager(browser()->profile()); 79 return factory_.GetManager(browser()->profile());
88 } 80 }
89 81
90 enum TestServer {
91 NEEDS_TEST_SERVER,
92 NO_TEST_SERVER
93 };
94
95 void TestHelper(const std::string& test_name, 82 void TestHelper(const std::string& test_name,
96 const std::string& app_location, 83 const std::string& app_location,
97 const std::string& app_to_embed, 84 const std::string& app_to_embed) {
98 TestServer test_server) {
99 // For serving guest pages.
100 if (test_server == NEEDS_TEST_SERVER) {
101 if (!StartEmbeddedTestServer()) {
102 LOG(ERROR) << "FAILED TO START TEST SERVER.";
103 return;
104 }
105 }
106
107 LoadAndLaunchPlatformApp(app_location.c_str(), "Launched"); 85 LoadAndLaunchPlatformApp(app_location.c_str(), "Launched");
108 86
109 // Flush any pending events to make sure we start with a clean slate. 87 // Flush any pending events to make sure we start with a clean slate.
110 content::RunAllPendingInMessageLoop(); 88 content::RunAllPendingInMessageLoop();
111 89
112 content::WebContents* embedder_web_contents = 90 content::WebContents* embedder_web_contents =
113 GetFirstAppWindowWebContents(); 91 GetFirstAppWindowWebContents();
114 if (!embedder_web_contents) { 92 if (!embedder_web_contents) {
115 LOG(ERROR) << "UNABLE TO FIND EMBEDDER WEB CONTENTS."; 93 LOG(ERROR) << "UNABLE TO FIND EMBEDDER WEB CONTENTS.";
116 return; 94 return;
117 } 95 }
118 96
119 ExtensionTestMessageListener done_listener("TEST_PASSED", false); 97 ExtensionTestMessageListener done_listener("TEST_PASSED", false);
120 done_listener.set_failure_message("TEST_FAILED"); 98 done_listener.set_failure_message("TEST_FAILED");
121 if (!content::ExecuteScript( 99 if (!content::ExecuteScript(
122 embedder_web_contents, 100 embedder_web_contents,
123 base::StringPrintf("runTest('%s', '%s')", 101 base::StringPrintf("runTest('%s', '%s')", test_name.c_str(),
124 test_name.c_str(),
125 app_to_embed.c_str()))) { 102 app_to_embed.c_str()))) {
126 LOG(ERROR) << "UNABLE TO START TEST."; 103 LOG(ERROR) << "UNABLE TO START TEST.";
127 return; 104 return;
128 } 105 }
129 ASSERT_TRUE(done_listener.WaitUntilSatisfied()); 106 ASSERT_TRUE(done_listener.WaitUntilSatisfied());
130 } 107 }
131 108
132 private: 109 private:
133 void SetUpCommandLine(base::CommandLine* command_line) override { 110 void SetUpCommandLine(base::CommandLine* command_line) override {
134 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); 111 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line);
135 } 112 }
136 113
137 TestGuestViewManagerFactory factory_; 114 TestGuestViewManagerFactory factory_;
138 }; 115 };
139 116
140 // Tests that <appview> is able to navigate to another installed app. 117 // Tests that <extensionview> can be created and added to the DOM.
141 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewWithUndefinedDataShouldSucceed) { 118 IN_PROC_BROWSER_TEST_F(ExtensionViewTest,
119 TestExtensionViewCreationShouldSucceed) {
142 const extensions::Extension* skeleton_app = 120 const extensions::Extension* skeleton_app =
143 InstallPlatformApp("app_view/shim/skeleton"); 121 InstallPlatformApp("extension_view/skeleton");
144 TestHelper("testAppViewWithUndefinedDataShouldSucceed", 122 TestHelper("testExtensionViewCreationShouldSucceed", "extension_view",
145 "app_view/shim", 123 skeleton_app->id());
146 skeleton_app->id(),
147 NO_TEST_SERVER);
148 } 124 }
149 125
150 // Tests that <appview> correctly processes parameters passed on connect. 126 // Tests that verify that <extensionview> can navigate to different sources.
151 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewRefusedDataShouldFail) { 127 IN_PROC_BROWSER_TEST_F(ExtensionViewTest, ShimSrcAttribute) {
152 const extensions::Extension* skeleton_app = 128 ASSERT_TRUE(RunPlatformAppTest("platform_apps/extension_view/src_attribute"));
153 InstallPlatformApp("app_view/shim/skeleton");
154 TestHelper("testAppViewRefusedDataShouldFail",
155 "app_view/shim",
156 skeleton_app->id(),
157 NO_TEST_SERVER);
158 } 129 }
159
160 // Tests that <appview> correctly processes parameters passed on connect.
161 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewGoodDataShouldSucceed) {
162 const extensions::Extension* skeleton_app =
163 InstallPlatformApp("app_view/shim/skeleton");
164 TestHelper("testAppViewGoodDataShouldSucceed",
165 "app_view/shim",
166 skeleton_app->id(),
167 NO_TEST_SERVER);
168 }
169
170 // Tests that <appview> correctly handles multiple successive connects.
171 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewMultipleConnects) {
172 const extensions::Extension* skeleton_app =
173 InstallPlatformApp("app_view/shim/skeleton");
174 TestHelper("testAppViewMultipleConnects",
175 "app_view/shim",
176 skeleton_app->id(),
177 NO_TEST_SERVER);
178 }
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698