Chromium Code Reviews| 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 "content/public/browser/notification_service.h" | 7 #include "content/public/browser/notification_service.h" |
| 8 #include "content/public/browser/render_process_host.h" | 8 #include "content/public/browser/render_process_host.h" |
| 9 #include "content/public/test/browser_test_utils.h" | 9 #include "content/public/test/browser_test_utils.h" |
| 10 #include "content/public/test/test_utils.h" | 10 #include "content/public/test/test_utils.h" |
| 11 #include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h " | |
|
Fady Samuel
2015/04/23 03:44:52
Note to self: This can be removed.
Fady Samuel
2015/04/24 00:11:31
Done.
| |
| 11 #include "extensions/browser/guest_view/guest_view_manager.h" | 12 #include "extensions/browser/guest_view/guest_view_manager.h" |
| 12 #include "extensions/browser/guest_view/guest_view_manager_factory.h" | 13 #include "extensions/browser/guest_view/guest_view_manager_factory.h" |
| 14 #include "extensions/browser/guest_view/test_guest_view_manager.h" | |
| 13 #include "extensions/common/switches.h" | 15 #include "extensions/common/switches.h" |
| 14 #include "extensions/test/extension_test_message_listener.h" | 16 #include "extensions/test/extension_test_message_listener.h" |
| 15 #include "net/test/embedded_test_server/embedded_test_server.h" | 17 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 16 #include "net/test/embedded_test_server/http_request.h" | 18 #include "net/test/embedded_test_server/http_request.h" |
| 17 #include "net/test/embedded_test_server/http_response.h" | 19 #include "net/test/embedded_test_server/http_response.h" |
| 18 | 20 |
| 19 namespace { | |
| 20 | |
| 21 class TestGuestViewManager : public extensions::GuestViewManager { | |
| 22 public: | |
| 23 explicit TestGuestViewManager(content::BrowserContext* context) : | |
| 24 extensions::GuestViewManager(context), | |
| 25 web_contents_(NULL) {} | |
| 26 | |
| 27 content::WebContents* WaitForGuestCreated() { | |
| 28 if (web_contents_) | |
| 29 return web_contents_; | |
| 30 | |
| 31 message_loop_runner_ = new content::MessageLoopRunner; | |
| 32 message_loop_runner_->Run(); | |
| 33 return web_contents_; | |
| 34 } | |
| 35 | |
| 36 private: | |
| 37 // GuestViewManager override: | |
| 38 void AddGuest(int guest_instance_id, | |
| 39 content::WebContents* guest_web_contents) override { | |
| 40 extensions::GuestViewManager::AddGuest( | |
| 41 guest_instance_id, guest_web_contents); | |
| 42 web_contents_ = guest_web_contents; | |
| 43 | |
| 44 if (message_loop_runner_.get()) | |
| 45 message_loop_runner_->Quit(); | |
| 46 } | |
| 47 | |
| 48 content::WebContents* web_contents_; | |
| 49 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
| 50 }; | |
| 51 | |
| 52 // Test factory for creating test instances of GuestViewManager. | |
| 53 class TestGuestViewManagerFactory : public extensions::GuestViewManagerFactory { | |
| 54 public: | |
| 55 TestGuestViewManagerFactory() : | |
| 56 test_guest_view_manager_(NULL) {} | |
| 57 | |
| 58 ~TestGuestViewManagerFactory() override {} | |
| 59 | |
| 60 extensions::GuestViewManager* CreateGuestViewManager( | |
| 61 content::BrowserContext* context) override { | |
| 62 return GetManager(context); | |
| 63 } | |
| 64 | |
| 65 TestGuestViewManager* GetManager(content::BrowserContext* context) { | |
| 66 if (!test_guest_view_manager_) { | |
| 67 test_guest_view_manager_ = new TestGuestViewManager(context); | |
| 68 } | |
| 69 return test_guest_view_manager_; | |
| 70 } | |
| 71 | |
| 72 private: | |
| 73 TestGuestViewManager* test_guest_view_manager_; | |
| 74 | |
| 75 DISALLOW_COPY_AND_ASSIGN(TestGuestViewManagerFactory); | |
| 76 }; | |
| 77 | |
| 78 } // namespace | |
| 79 | |
| 80 class AppViewTest : public extensions::PlatformAppBrowserTest { | 21 class AppViewTest : public extensions::PlatformAppBrowserTest { |
| 81 public: | 22 public: |
| 82 AppViewTest() { | 23 AppViewTest() { |
| 83 extensions::GuestViewManager::set_factory_for_testing(&factory_); | 24 extensions::GuestViewManager::set_factory_for_testing(&factory_); |
| 84 } | 25 } |
| 85 | 26 |
| 86 TestGuestViewManager* GetGuestViewManager() { | |
| 87 return factory_.GetManager(browser()->profile()); | |
| 88 } | |
| 89 | |
| 90 enum TestServer { | 27 enum TestServer { |
| 91 NEEDS_TEST_SERVER, | 28 NEEDS_TEST_SERVER, |
| 92 NO_TEST_SERVER | 29 NO_TEST_SERVER |
| 93 }; | 30 }; |
| 94 | 31 |
| 95 void TestHelper(const std::string& test_name, | 32 void TestHelper(const std::string& test_name, |
| 96 const std::string& app_location, | 33 const std::string& app_location, |
| 97 const std::string& app_to_embed, | 34 const std::string& app_to_embed, |
| 98 TestServer test_server) { | 35 TestServer test_server) { |
| 99 // For serving guest pages. | 36 // For serving guest pages. |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 127 return; | 64 return; |
| 128 } | 65 } |
| 129 ASSERT_TRUE(done_listener.WaitUntilSatisfied()); | 66 ASSERT_TRUE(done_listener.WaitUntilSatisfied()); |
| 130 } | 67 } |
| 131 | 68 |
| 132 private: | 69 private: |
| 133 void SetUpCommandLine(base::CommandLine* command_line) override { | 70 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 134 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); | 71 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); |
| 135 } | 72 } |
| 136 | 73 |
| 137 TestGuestViewManagerFactory factory_; | 74 extensions::TestGuestViewManagerFactory factory_; |
| 138 }; | 75 }; |
| 139 | 76 |
| 140 // Tests that <appview> is able to navigate to another installed app. | 77 // Tests that <appview> is able to navigate to another installed app. |
| 141 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewWithUndefinedDataShouldSucceed) { | 78 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewWithUndefinedDataShouldSucceed) { |
| 142 const extensions::Extension* skeleton_app = | 79 const extensions::Extension* skeleton_app = |
| 143 InstallPlatformApp("app_view/shim/skeleton"); | 80 InstallPlatformApp("app_view/shim/skeleton"); |
| 144 TestHelper("testAppViewWithUndefinedDataShouldSucceed", | 81 TestHelper("testAppViewWithUndefinedDataShouldSucceed", |
| 145 "app_view/shim", | 82 "app_view/shim", |
| 146 skeleton_app->id(), | 83 skeleton_app->id(), |
| 147 NO_TEST_SERVER); | 84 NO_TEST_SERVER); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 169 | 106 |
| 170 // Tests that <appview> correctly handles multiple successive connects. | 107 // Tests that <appview> correctly handles multiple successive connects. |
| 171 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewMultipleConnects) { | 108 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewMultipleConnects) { |
| 172 const extensions::Extension* skeleton_app = | 109 const extensions::Extension* skeleton_app = |
| 173 InstallPlatformApp("app_view/shim/skeleton"); | 110 InstallPlatformApp("app_view/shim/skeleton"); |
| 174 TestHelper("testAppViewMultipleConnects", | 111 TestHelper("testAppViewMultipleConnects", |
| 175 "app_view/shim", | 112 "app_view/shim", |
| 176 skeleton_app->id(), | 113 skeleton_app->id(), |
| 177 NO_TEST_SERVER); | 114 NO_TEST_SERVER); |
| 178 } | 115 } |
| OLD | NEW |