| 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" | 5 #include "extensions/browser/guest_view/web_view/web_view_apitest.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 const char kRedirectResponsePath[] = "/server-redirect"; | 48 const char kRedirectResponsePath[] = "/server-redirect"; |
| 49 const char kRedirectResponseFullPath[] = "/guest_redirect.html"; | 49 const char kRedirectResponseFullPath[] = "/guest_redirect.html"; |
| 50 const char kUserAgentRedirectResponsePath[] = "/detect-user-agent"; | 50 const char kUserAgentRedirectResponsePath[] = "/detect-user-agent"; |
| 51 const char kTestDataDirectory[] = "testDataDirectory"; | 51 const char kTestDataDirectory[] = "testDataDirectory"; |
| 52 const char kTestServerPort[] = "testServer.port"; | 52 const char kTestServerPort[] = "testServer.port"; |
| 53 const char kTestWebSocketPort[] = "testWebSocketPort"; | 53 const char kTestWebSocketPort[] = "testWebSocketPort"; |
| 54 const char kIsolateExtensions[] = "isolateExtensions"; | 54 const char kIsolateExtensions[] = "isolateExtensions"; |
| 55 | 55 |
| 56 // Handles |request| by serving a redirect response if the |User-Agent| is | 56 // Handles |request| by serving a redirect response if the |User-Agent| is |
| 57 // foobar. | 57 // foobar. |
| 58 static scoped_ptr<net::test_server::HttpResponse> UserAgentResponseHandler( | 58 static std::unique_ptr<net::test_server::HttpResponse> UserAgentResponseHandler( |
| 59 const std::string& path, | 59 const std::string& path, |
| 60 const GURL& redirect_target, | 60 const GURL& redirect_target, |
| 61 const net::test_server::HttpRequest& request) { | 61 const net::test_server::HttpRequest& request) { |
| 62 if (!base::StartsWith(path, request.relative_url, | 62 if (!base::StartsWith(path, request.relative_url, |
| 63 base::CompareCase::SENSITIVE)) | 63 base::CompareCase::SENSITIVE)) |
| 64 return scoped_ptr<net::test_server::HttpResponse>(); | 64 return std::unique_ptr<net::test_server::HttpResponse>(); |
| 65 | 65 |
| 66 auto it = request.headers.find("User-Agent"); | 66 auto it = request.headers.find("User-Agent"); |
| 67 EXPECT_TRUE(it != request.headers.end()); | 67 EXPECT_TRUE(it != request.headers.end()); |
| 68 if (!base::StartsWith("foobar", it->second, base::CompareCase::SENSITIVE)) | 68 if (!base::StartsWith("foobar", it->second, base::CompareCase::SENSITIVE)) |
| 69 return scoped_ptr<net::test_server::HttpResponse>(); | 69 return std::unique_ptr<net::test_server::HttpResponse>(); |
| 70 | 70 |
| 71 scoped_ptr<net::test_server::BasicHttpResponse> http_response( | 71 std::unique_ptr<net::test_server::BasicHttpResponse> http_response( |
| 72 new net::test_server::BasicHttpResponse); | 72 new net::test_server::BasicHttpResponse); |
| 73 http_response->set_code(net::HTTP_MOVED_PERMANENTLY); | 73 http_response->set_code(net::HTTP_MOVED_PERMANENTLY); |
| 74 http_response->AddCustomHeader("Location", redirect_target.spec()); | 74 http_response->AddCustomHeader("Location", redirect_target.spec()); |
| 75 return std::move(http_response); | 75 return std::move(http_response); |
| 76 } | 76 } |
| 77 | 77 |
| 78 class WebContentsHiddenObserver : public content::WebContentsObserver { | 78 class WebContentsHiddenObserver : public content::WebContentsObserver { |
| 79 public: | 79 public: |
| 80 WebContentsHiddenObserver(content::WebContents* web_contents, | 80 WebContentsHiddenObserver(content::WebContents* web_contents, |
| 81 const base::Closure& hidden_callback) | 81 const base::Closure& hidden_callback) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 93 bool hidden_observed() { return hidden_observed_; } | 93 bool hidden_observed() { return hidden_observed_; } |
| 94 | 94 |
| 95 private: | 95 private: |
| 96 base::Closure hidden_callback_; | 96 base::Closure hidden_callback_; |
| 97 bool hidden_observed_; | 97 bool hidden_observed_; |
| 98 | 98 |
| 99 DISALLOW_COPY_AND_ASSIGN(WebContentsHiddenObserver); | 99 DISALLOW_COPY_AND_ASSIGN(WebContentsHiddenObserver); |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 // Handles |request| by serving a redirect response. | 102 // Handles |request| by serving a redirect response. |
| 103 scoped_ptr<net::test_server::HttpResponse> RedirectResponseHandler( | 103 std::unique_ptr<net::test_server::HttpResponse> RedirectResponseHandler( |
| 104 const std::string& path, | 104 const std::string& path, |
| 105 const GURL& redirect_target, | 105 const GURL& redirect_target, |
| 106 const net::test_server::HttpRequest& request) { | 106 const net::test_server::HttpRequest& request) { |
| 107 if (!base::StartsWith(path, request.relative_url, | 107 if (!base::StartsWith(path, request.relative_url, |
| 108 base::CompareCase::SENSITIVE)) | 108 base::CompareCase::SENSITIVE)) |
| 109 return scoped_ptr<net::test_server::HttpResponse>(); | 109 return std::unique_ptr<net::test_server::HttpResponse>(); |
| 110 | 110 |
| 111 scoped_ptr<net::test_server::BasicHttpResponse> http_response( | 111 std::unique_ptr<net::test_server::BasicHttpResponse> http_response( |
| 112 new net::test_server::BasicHttpResponse); | 112 new net::test_server::BasicHttpResponse); |
| 113 http_response->set_code(net::HTTP_MOVED_PERMANENTLY); | 113 http_response->set_code(net::HTTP_MOVED_PERMANENTLY); |
| 114 http_response->AddCustomHeader("Location", redirect_target.spec()); | 114 http_response->AddCustomHeader("Location", redirect_target.spec()); |
| 115 return std::move(http_response); | 115 return std::move(http_response); |
| 116 } | 116 } |
| 117 | 117 |
| 118 // Handles |request| by serving an empty response. | 118 // Handles |request| by serving an empty response. |
| 119 scoped_ptr<net::test_server::HttpResponse> EmptyResponseHandler( | 119 std::unique_ptr<net::test_server::HttpResponse> EmptyResponseHandler( |
| 120 const std::string& path, | 120 const std::string& path, |
| 121 const net::test_server::HttpRequest& request) { | 121 const net::test_server::HttpRequest& request) { |
| 122 if (base::StartsWith(path, request.relative_url, | 122 if (base::StartsWith(path, request.relative_url, |
| 123 base::CompareCase::SENSITIVE)) { | 123 base::CompareCase::SENSITIVE)) { |
| 124 return scoped_ptr<net::test_server::HttpResponse>( | 124 return std::unique_ptr<net::test_server::HttpResponse>( |
| 125 new net::test_server::RawHttpResponse("", "")); | 125 new net::test_server::RawHttpResponse("", "")); |
| 126 } | 126 } |
| 127 | 127 |
| 128 return scoped_ptr<net::test_server::HttpResponse>(); | 128 return std::unique_ptr<net::test_server::HttpResponse>(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 } // namespace | 131 } // namespace |
| 132 | 132 |
| 133 namespace extensions { | 133 namespace extensions { |
| 134 | 134 |
| 135 WebViewAPITest::WebViewAPITest() { | 135 WebViewAPITest::WebViewAPITest() { |
| 136 GuestViewManager::set_factory_for_testing(&factory_); | 136 GuestViewManager::set_factory_for_testing(&factory_); |
| 137 } | 137 } |
| 138 | 138 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 context, | 262 context, |
| 263 ExtensionsAPIClient::Get()->CreateGuestViewManagerDelegate( | 263 ExtensionsAPIClient::Get()->CreateGuestViewManagerDelegate( |
| 264 context))); | 264 context))); |
| 265 } | 265 } |
| 266 return manager; | 266 return manager; |
| 267 } | 267 } |
| 268 | 268 |
| 269 void WebViewAPITest::SendMessageToGuestAndWait( | 269 void WebViewAPITest::SendMessageToGuestAndWait( |
| 270 const std::string& message, | 270 const std::string& message, |
| 271 const std::string& wait_message) { | 271 const std::string& wait_message) { |
| 272 scoped_ptr<ExtensionTestMessageListener> listener; | 272 std::unique_ptr<ExtensionTestMessageListener> listener; |
| 273 if (!wait_message.empty()) | 273 if (!wait_message.empty()) |
| 274 listener.reset(new ExtensionTestMessageListener(wait_message, false)); | 274 listener.reset(new ExtensionTestMessageListener(wait_message, false)); |
| 275 | 275 |
| 276 EXPECT_TRUE( | 276 EXPECT_TRUE( |
| 277 content::ExecuteScript( | 277 content::ExecuteScript( |
| 278 GetGuestWebContents(), | 278 GetGuestWebContents(), |
| 279 base::StringPrintf("onAppCommand('%s');", message.c_str()))); | 279 base::StringPrintf("onAppCommand('%s');", message.c_str()))); |
| 280 | 280 |
| 281 if (listener) | 281 if (listener) |
| 282 ASSERT_TRUE(listener->WaitUntilSatisfied()); | 282 ASSERT_TRUE(listener->WaitUntilSatisfied()); |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 // This test verifies that webview.contentWindow works inside an iframe | 734 // This test verifies that webview.contentWindow works inside an iframe |
| 735 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestWebViewInsideFrame) { | 735 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestWebViewInsideFrame) { |
| 736 LaunchApp("web_view/inside_iframe"); | 736 LaunchApp("web_view/inside_iframe"); |
| 737 } | 737 } |
| 738 | 738 |
| 739 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestCaptureVisibleRegion) { | 739 IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestCaptureVisibleRegion) { |
| 740 RunTest("testCaptureVisibleRegion", "web_view/apitest"); | 740 RunTest("testCaptureVisibleRegion", "web_view/apitest"); |
| 741 } | 741 } |
| 742 | 742 |
| 743 } // namespace extensions | 743 } // namespace extensions |
| OLD | NEW |