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 "extensions/browser/guest_view/web_view/web_view_apitest.h" | |
| 6 | |
| 5 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 6 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 7 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 8 #include "content/public/browser/render_process_host.h" | 10 #include "content/public/browser/render_process_host.h" |
| 9 #include "content/public/test/browser_test_utils.h" | 11 #include "content/public/test/browser_test_utils.h" |
| 10 #include "content/public/test/test_utils.h" | 12 #include "content/public/test/test_utils.h" |
| 11 #include "extensions/browser/api/test/test_api.h" | 13 #include "extensions/browser/api/test/test_api.h" |
| 12 #include "extensions/browser/app_window/app_window.h" | 14 #include "extensions/browser/app_window/app_window.h" |
| 13 #include "extensions/browser/app_window/app_window_registry.h" | 15 #include "extensions/browser/app_window/app_window_registry.h" |
| 14 #include "extensions/browser/extension_host.h" | 16 #include "extensions/browser/extension_host.h" |
| 15 #include "extensions/browser/guest_view/guest_view_manager.h" | 17 #include "extensions/browser/guest_view/guest_view_manager.h" |
| 16 #include "extensions/browser/guest_view/guest_view_manager_factory.h" | 18 #include "extensions/browser/guest_view/guest_view_manager_factory.h" |
| 17 #include "extensions/browser/guest_view/web_view/test_guest_view_manager.h" | 19 #include "extensions/browser/guest_view/test_guest_view_manager.h" |
| 18 #include "extensions/browser/process_manager.h" | 20 #include "extensions/browser/process_manager.h" |
| 19 #include "extensions/common/extension.h" | 21 #include "extensions/common/extension.h" |
| 20 #include "extensions/common/extension_paths.h" | 22 #include "extensions/common/extension_paths.h" |
| 21 #include "extensions/shell/browser/shell_content_browser_client.h" | 23 #include "extensions/shell/browser/shell_content_browser_client.h" |
| 22 #include "extensions/shell/browser/shell_extension_system.h" | 24 #include "extensions/shell/browser/shell_extension_system.h" |
| 23 #include "extensions/shell/test/shell_test.h" | 25 #include "extensions/shell/test/shell_test.h" |
| 24 #include "extensions/test/extension_test_message_listener.h" | 26 #include "extensions/test/extension_test_message_listener.h" |
| 25 #include "net/base/filename_util.h" | 27 #include "net/base/filename_util.h" |
| 26 #include "net/test/embedded_test_server/embedded_test_server.h" | 28 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 27 #include "net/test/embedded_test_server/http_request.h" | 29 #include "net/test/embedded_test_server/http_request.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 return scoped_ptr<net::test_server::HttpResponse>(new EmptyHttpResponse); | 68 return scoped_ptr<net::test_server::HttpResponse>(new EmptyHttpResponse); |
| 67 } | 69 } |
| 68 | 70 |
| 69 return scoped_ptr<net::test_server::HttpResponse>(); | 71 return scoped_ptr<net::test_server::HttpResponse>(); |
| 70 } | 72 } |
| 71 | 73 |
| 72 } // namespace | 74 } // namespace |
| 73 | 75 |
| 74 namespace extensions { | 76 namespace extensions { |
| 75 | 77 |
| 76 // This class intercepts download request from the guest. | 78 void WebViewAPITest::LaunchApp(const std::string& app_location) { |
| 77 class WebViewAPITest : public AppShellTest { | 79 base::FilePath test_data_dir; |
| 78 protected: | 80 PathService::Get(DIR_TEST_DATA, &test_data_dir); |
| 79 void LaunchApp(const std::string& app_location) { | 81 test_data_dir = test_data_dir.AppendASCII(app_location.c_str()); |
| 80 base::FilePath test_data_dir; | |
| 81 PathService::Get(DIR_TEST_DATA, &test_data_dir); | |
| 82 test_data_dir = test_data_dir.AppendASCII(app_location.c_str()); | |
| 83 | 82 |
| 84 test_config_.SetString(kTestDataDirectory, | 83 test_config_.SetString(kTestDataDirectory, |
| 85 net::FilePathToFileURL(test_data_dir).spec()); | 84 net::FilePathToFileURL(test_data_dir).spec()); |
| 86 | 85 |
| 87 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); | 86 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); |
| 88 | 87 |
| 89 ASSERT_TRUE(extension_system_->LoadApp(test_data_dir)); | 88 ASSERT_TRUE(extension_system_->LoadApp(test_data_dir)); |
| 90 extension_system_->LaunchApp(); | 89 extension_system_->LaunchApp(); |
| 91 | 90 |
| 92 ExtensionTestMessageListener launch_listener("LAUNCHED", false); | 91 ExtensionTestMessageListener launch_listener("LAUNCHED", false); |
| 93 ASSERT_TRUE(launch_listener.WaitUntilSatisfied()); | 92 ASSERT_TRUE(launch_listener.WaitUntilSatisfied()); |
| 94 | 93 |
| 95 const AppWindowRegistry::AppWindowList& app_window_list = | 94 const AppWindowRegistry::AppWindowList& app_window_list = |
| 96 AppWindowRegistry::Get(browser_context_)->app_windows(); | 95 AppWindowRegistry::Get(browser_context_)->app_windows(); |
| 97 DCHECK(app_window_list.size() == 1); | 96 DCHECK(app_window_list.size() == 1); |
| 98 embedder_web_contents_ = (*app_window_list.begin())->web_contents(); | 97 embedder_web_contents_ = (*app_window_list.begin())->web_contents(); |
| 98 } | |
| 99 | |
| 100 void WebViewAPITest::RunTest(const std::string& test_name, | |
| 101 const std::string& app_location) { | |
| 102 LaunchApp(app_location); | |
| 103 | |
| 104 ExtensionTestMessageListener done_listener("TEST_PASSED", false); | |
| 105 done_listener.set_failure_message("TEST_FAILED"); | |
| 106 if (!content::ExecuteScript( | |
| 107 embedder_web_contents_, | |
| 108 base::StringPrintf("runTest('%s')", test_name.c_str()))) { | |
| 109 LOG(ERROR) << "Unable to start test."; | |
| 110 return; | |
| 111 } | |
| 112 ASSERT_TRUE(done_listener.WaitUntilSatisfied()); | |
| 113 } | |
| 114 | |
| 115 void WebViewAPITest::SetUpOnMainThread() { | |
| 116 AppShellTest::SetUpOnMainThread(); | |
| 117 | |
| 118 TestGetConfigFunction::set_test_config_state(&test_config_); | |
| 119 base::FilePath test_data_dir; | |
| 120 test_config_.SetInteger(kTestWebSocketPort, 0); | |
| 121 } | |
| 122 | |
| 123 void WebViewAPITest::StartTestServer() { | |
| 124 // For serving guest pages. | |
| 125 if (!embedded_test_server()->InitializeAndWaitUntilReady()) { | |
| 126 LOG(ERROR) << "Failed to start test server."; | |
| 127 return; | |
| 99 } | 128 } |
| 100 | 129 |
| 101 void RunTest(const std::string& test_name, const std::string& app_location) { | 130 test_config_.SetInteger(kTestServerPort, embedded_test_server()->port()); |
| 102 LaunchApp(app_location); | |
| 103 | 131 |
| 104 ExtensionTestMessageListener done_listener("TEST_PASSED", false); | 132 embedded_test_server()->RegisterRequestHandler( |
| 105 done_listener.set_failure_message("TEST_FAILED"); | 133 base::Bind(&RedirectResponseHandler, |
| 106 if (!content::ExecuteScript( | 134 kRedirectResponsePath, |
| 107 embedder_web_contents_, | 135 embedded_test_server()->GetURL(kRedirectResponseFullPath))); |
| 108 base::StringPrintf("runTest('%s')", test_name.c_str()))) { | 136 |
| 109 LOG(ERROR) << "Unable to start test."; | 137 embedded_test_server()->RegisterRequestHandler( |
| 110 return; | 138 base::Bind(&EmptyResponseHandler, kEmptyResponsePath)); |
| 111 } | 139 } |
| 112 ASSERT_TRUE(done_listener.WaitUntilSatisfied()); | 140 |
| 141 void WebViewAPITest::StopTestServer() { | |
| 142 if (!embedded_test_server()->ShutdownAndWaitUntilComplete()) { | |
| 143 LOG(ERROR) << "Failed to shutdown test server."; | |
| 113 } | 144 } |
| 145 } | |
| 114 | 146 |
| 115 virtual void SetUpOnMainThread() override { | 147 void WebViewAPITest::TearDownOnMainThread() { |
| 116 AppShellTest::SetUpOnMainThread(); | 148 TestGetConfigFunction::set_test_config_state(nullptr); |
| 117 | 149 |
| 118 TestGetConfigFunction::set_test_config_state(&test_config_); | 150 AppShellTest::TearDownOnMainThread(); |
| 119 base::FilePath test_data_dir; | 151 } |
| 120 test_config_.SetInteger(kTestWebSocketPort, 0); | |
| 121 } | |
| 122 | 152 |
| 123 void StartTestServer() { | 153 TestGuestViewManager* WebViewAPITest::GetGuestViewManager() { |
| 124 // For serving guest pages. | 154 return static_cast<TestGuestViewManager*>( |
| 125 if (!embedded_test_server()->InitializeAndWaitUntilReady()) { | 155 TestGuestViewManager::FromBrowserContext( |
| 126 LOG(ERROR) << "Failed to start test server."; | 156 ShellContentBrowserClient::Get()->GetBrowserContext())); |
| 127 return; | 157 } |
| 128 } | |
| 129 | 158 |
| 130 test_config_.SetInteger(kTestServerPort, embedded_test_server()->port()); | 159 WebViewAPITest::WebViewAPITest() { |
|
lazyboy
2014/10/06 16:21:20
Move constructor at the very beginning.
lfg
2014/10/06 16:53:18
Done.
| |
| 131 | 160 GuestViewManager::set_factory_for_testing(&factory_); |
| 132 embedded_test_server()->RegisterRequestHandler( | 161 } |
| 133 base::Bind(&RedirectResponseHandler, | |
| 134 kRedirectResponsePath, | |
| 135 embedded_test_server()->GetURL(kRedirectResponseFullPath))); | |
| 136 | |
| 137 embedded_test_server()->RegisterRequestHandler( | |
| 138 base::Bind(&EmptyResponseHandler, kEmptyResponsePath)); | |
| 139 } | |
| 140 | |
| 141 void StopTestServer() { | |
| 142 if (!embedded_test_server()->ShutdownAndWaitUntilComplete()) { | |
| 143 LOG(ERROR) << "Failed to shutdown test server."; | |
| 144 } | |
| 145 } | |
| 146 | |
| 147 virtual void TearDownOnMainThread() override { | |
| 148 TestGetConfigFunction::set_test_config_state(nullptr); | |
| 149 | |
| 150 AppShellTest::TearDownOnMainThread(); | |
| 151 } | |
| 152 | |
| 153 TestGuestViewManager* GetGuestViewManager() { | |
| 154 return static_cast<TestGuestViewManager*>( | |
| 155 TestGuestViewManager::FromBrowserContext( | |
| 156 ShellContentBrowserClient::Get()->GetBrowserContext())); | |
| 157 } | |
| 158 | |
| 159 WebViewAPITest() { GuestViewManager::set_factory_for_testing(&factory_); } | |
| 160 | |
| 161 protected: | |
| 162 content::WebContents* embedder_web_contents_; | |
| 163 TestGuestViewManagerFactory factory_; | |
| 164 base::DictionaryValue test_config_; | |
| 165 }; | |
| 166 | 162 |
| 167 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestAllowTransparencyAttribute) { | 163 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestAllowTransparencyAttribute) { |
| 168 RunTest("testAllowTransparencyAttribute", "web_view/apitest"); | 164 RunTest("testAllowTransparencyAttribute", "web_view/apitest"); |
| 169 } | 165 } |
| 170 | 166 |
| 171 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestAPIMethodExistence) { | 167 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestAPIMethodExistence) { |
| 172 RunTest("testAPIMethodExistence", "web_view/apitest"); | 168 RunTest("testAPIMethodExistence", "web_view/apitest"); |
| 173 } | 169 } |
| 174 | 170 |
| 175 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestAssignSrcAfterCrash) { | 171 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestAssignSrcAfterCrash) { |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 | 412 |
| 417 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestResizeWebviewResizesContent) { | 413 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestResizeWebviewResizesContent) { |
| 418 RunTest("testResizeWebviewResizesContent", "web_view/apitest"); | 414 RunTest("testResizeWebviewResizesContent", "web_view/apitest"); |
| 419 } | 415 } |
| 420 | 416 |
| 421 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestTerminateAfterExit) { | 417 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestTerminateAfterExit) { |
| 422 RunTest("testTerminateAfterExit", "web_view/apitest"); | 418 RunTest("testTerminateAfterExit", "web_view/apitest"); |
| 423 } | 419 } |
| 424 | 420 |
| 425 } // namespace extensions | 421 } // namespace extensions |
| OLD | NEW |