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

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

Issue 1066563006: GuestView: Move GuestViewManager extension dependencies to ExtensionsGuestViewManagerDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@extensions_guest_view_message_filter
Patch Set: Fixed NavigateGuest Created 5 years, 8 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
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 "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 { 15 using extensions::ExtensionsGuestViewManagerDelegate;
14 16 using extensions::GuestViewManager;
15 class TestGuestViewManager : public extensions::GuestViewManager { 17 using extensions::TestGuestViewManager;
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 18
72 class ExtensionViewTest : public extensions::PlatformAppBrowserTest { 19 class ExtensionViewTest : public extensions::PlatformAppBrowserTest {
73 public: 20 public:
74 ExtensionViewTest() { 21 ExtensionViewTest() {
75 extensions::GuestViewManager::set_factory_for_testing(&factory_); 22 extensions::GuestViewManager::set_factory_for_testing(&factory_);
76 } 23 }
77 24
78 TestGuestViewManager* GetGuestViewManager() { 25 extensions::TestGuestViewManager* GetGuestViewManager() {
79 return factory_.GetManager(browser()->profile()); 26 TestGuestViewManager* manager = static_cast<TestGuestViewManager*>(
27 TestGuestViewManager::FromBrowserContext(browser()->profile()));
28 // TestGuestViewManager::WaitForSingleGuestCreated may and will get called
29 // before a guest is created.
30 if (!manager) {
31 manager = static_cast<TestGuestViewManager*>(
32 GuestViewManager::CreateWithDelegate(
33 browser()->profile(),
34 scoped_ptr<guestview::GuestViewManagerDelegate>(
35 new ExtensionsGuestViewManagerDelegate(
36 browser()->profile()))));
37 }
38 return manager;
80 } 39 }
81 40
82 void TestHelper(const std::string& test_name, 41 void TestHelper(const std::string& test_name,
83 const std::string& app_location, 42 const std::string& app_location,
84 const std::string& app_to_embed) { 43 const std::string& app_to_embed) {
85 LoadAndLaunchPlatformApp(app_location.c_str(), "Launched"); 44 LoadAndLaunchPlatformApp(app_location.c_str(), "Launched");
86 45
87 // Flush any pending events to make sure we start with a clean slate. 46 // Flush any pending events to make sure we start with a clean slate.
88 content::RunAllPendingInMessageLoop(); 47 content::RunAllPendingInMessageLoop();
89 48
(...skipping 14 matching lines...) Expand all
104 return; 63 return;
105 } 64 }
106 ASSERT_TRUE(done_listener.WaitUntilSatisfied()); 65 ASSERT_TRUE(done_listener.WaitUntilSatisfied());
107 } 66 }
108 67
109 private: 68 private:
110 void SetUpCommandLine(base::CommandLine* command_line) override { 69 void SetUpCommandLine(base::CommandLine* command_line) override {
111 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); 70 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line);
112 } 71 }
113 72
114 TestGuestViewManagerFactory factory_; 73 extensions::TestGuestViewManagerFactory factory_;
115 }; 74 };
116 75
117 // Tests that <extensionview> can be created and added to the DOM. 76 // Tests that <extensionview> can be created and added to the DOM.
118 IN_PROC_BROWSER_TEST_F(ExtensionViewTest, 77 IN_PROC_BROWSER_TEST_F(ExtensionViewTest,
119 TestExtensionViewCreationShouldSucceed) { 78 TestExtensionViewCreationShouldSucceed) {
120 const extensions::Extension* skeleton_app = 79 const extensions::Extension* skeleton_app =
121 InstallPlatformApp("extension_view/skeleton"); 80 InstallPlatformApp("extension_view/skeleton");
122 TestHelper("testExtensionViewCreationShouldSucceed", "extension_view", 81 TestHelper("testExtensionViewCreationShouldSucceed", "extension_view",
123 skeleton_app->id()); 82 skeleton_app->id());
124 } 83 }
125 84
126 // Tests that verify that <extensionview> can navigate to different sources. 85 // Tests that verify that <extensionview> can navigate to different sources.
127 IN_PROC_BROWSER_TEST_F(ExtensionViewTest, ShimSrcAttribute) { 86 IN_PROC_BROWSER_TEST_F(ExtensionViewTest, ShimSrcAttribute) {
128 ASSERT_TRUE(RunPlatformAppTest( 87 ASSERT_TRUE(RunPlatformAppTest(
129 "platform_apps/extension_view/src_attribute")); 88 "platform_apps/extension_view/src_attribute"));
130 } 89 }
131 90
132 // Tests that verify that <extensionview> can call the connect function. 91 // Tests that verify that <extensionview> can call the connect function.
133 IN_PROC_BROWSER_TEST_F(ExtensionViewTest, ConnectAPICall) { 92 IN_PROC_BROWSER_TEST_F(ExtensionViewTest, ConnectAPICall) {
134 ASSERT_TRUE(RunPlatformAppTest("platform_apps/extension_view/connect_api")); 93 ASSERT_TRUE(RunPlatformAppTest("platform_apps/extension_view/connect_api"));
135 } 94 }
136 95
137 // Tests that verify that <extensionview> does not change extension ID if 96 // Tests that verify that <extensionview> does not change extension ID if
138 // someone tries to change it in JavaScript. 97 // someone tries to change it in JavaScript.
139 IN_PROC_BROWSER_TEST_F(ExtensionViewTest, ShimExtensionAttribute) { 98 IN_PROC_BROWSER_TEST_F(ExtensionViewTest, ShimExtensionAttribute) {
140 ASSERT_TRUE(RunPlatformAppTest( 99 ASSERT_TRUE(RunPlatformAppTest(
141 "platform_apps/extension_view/extension_attribute")); 100 "platform_apps/extension_view/extension_attribute"));
142 } 101 }
OLDNEW
« no previous file with comments | « chrome/browser/apps/guest_view/app_view_browsertest.cc ('k') | chrome/browser/apps/guest_view/web_view_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698