diff options
Diffstat (limited to 'chromium/content/browser/conversions/conversions_browsertest.cc')
-rw-r--r-- | chromium/content/browser/conversions/conversions_browsertest.cc | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/chromium/content/browser/conversions/conversions_browsertest.cc b/chromium/content/browser/conversions/conversions_browsertest.cc index dedcf5a42ec..6df8d3c536f 100644 --- a/chromium/content/browser/conversions/conversions_browsertest.cc +++ b/chromium/content/browser/conversions/conversions_browsertest.cc @@ -5,7 +5,12 @@ #include <memory> #include "base/command_line.h" +#include "base/sequenced_task_runner.h" #include "base/test/scoped_feature_list.h" +#include "base/threading/sequenced_task_runner_handle.h" +#include "content/browser/conversions/conversion_manager_impl.h" +#include "content/browser/conversions/conversion_test_utils.h" +#include "content/public/common/content_client.h" #include "content/public/common/content_features.h" #include "content/public/common/content_switches.h" #include "content/public/test/browser_test.h" @@ -14,6 +19,7 @@ #include "content/public/test/content_browser_test_utils.h" #include "content/public/test/test_navigation_observer.h" #include "content/shell/browser/shell.h" +#include "content/test/test_content_browser_client.h" #include "net/dns/mock_host_resolver.h" #include "net/test/embedded_test_server/controllable_http_response.h" #include "net/test/embedded_test_server/default_handlers.h" @@ -45,6 +51,8 @@ struct ExpectedReportWaiter { GURL expected_url; std::unique_ptr<net::test_server::ControllableHttpResponse> response; + bool HasRequest() { return !!response->http_request(); } + // Returns the url for the HttpRequest handled by |response|. This returns a // URL formatted with the host defined in the headers. This would not match // |expected_url| if the host for report url was not set properly. @@ -74,10 +82,15 @@ class ConversionsBrowserTest : public ContentBrowserTest { public: ConversionsBrowserTest() { feature_list_.InitAndEnableFeature(features::kConversionMeasurement); + ConversionManagerImpl::RunInMemoryForTesting(); } void SetUpCommandLine(base::CommandLine* command_line) override { command_line->AppendSwitch(switches::kConversionsDebugMode); + + // Sets up the blink runtime feature for ConversionMeasurement. + command_line->AppendSwitch( + switches::kEnableExperimentalWebPlatformFeatures); } void SetUpOnMainThread() override { @@ -95,11 +108,19 @@ class ConversionsBrowserTest : public ContentBrowserTest { net::EmbeddedTestServer* https_server() { return https_server_.get(); } + protected: + ConversionDisallowingContentBrowserClient disallowed_browser_client_; + private: base::test::ScopedFeatureList feature_list_; std::unique_ptr<net::EmbeddedTestServer> https_server_; }; +// Verifies that storage initialization does not hang when initialized in a +// browsertest context, see https://crbug.com/1080764). +IN_PROC_BROWSER_TEST_F(ConversionsBrowserTest, + FeatureEnabled_StorageInitWithoutHang) {} + IN_PROC_BROWSER_TEST_F(ConversionsBrowserTest, ImpressionConversion_ReportSent) { // Expected reports must be registered before the server starts. @@ -251,4 +272,57 @@ IN_PROC_BROWSER_TEST_F( } } +IN_PROC_BROWSER_TEST_F(ConversionsBrowserTest, + ConversionRegisteredWithEmbedderDisallow_NoData) { + ContentBrowserClient* old_browser_client = + SetBrowserClientForTesting(&disallowed_browser_client_); + + // Expected reports must be registered before the server starts. + ExpectedReportWaiter expected_report( + GURL( + "https://a.test/.well-known/" + "register-conversion?impression-data=1&conversion-data=7&credit=100"), + https_server()); + ASSERT_TRUE(https_server()->Start()); + + GURL impression_url = https_server()->GetURL( + "a.test", "/conversions/page_with_impression_creator.html"); + EXPECT_TRUE(NavigateToURL(web_contents(), impression_url)); + + // Create an anchor tag with impression attributes and click the link. By + // default the target is set to "_top". + GURL conversion_url = https_server()->GetURL( + "b.test", "/conversions/page_with_conversion_redirect.html"); + EXPECT_TRUE( + ExecJs(web_contents(), + JsReplace(R"( + createImpressionTag("link" /* id */, + $1 /* url */, + "1" /* impression data */, + $2 /* conversion_destination */);)", + conversion_url, url::Origin::Create(conversion_url)))); + + TestNavigationObserver observer(web_contents()); + EXPECT_TRUE(ExecJs(shell(), "simulateClick('link');")); + observer.Wait(); + + // Register a conversion with the original page as the reporting origin. + EXPECT_TRUE( + ExecJs(web_contents(), JsReplace("registerConversionForOrigin(7, $1)", + url::Origin::Create(impression_url)))); + + // Since we want to verify that a report _isn't_ sent, we can't really wait on + // any event here. The best thing we can do is just impose a short delay and + // verify the browser didn't send anything. Worst case, this should start + // flakily failing if the logic breaks. + base::RunLoop run_loop; + base::SequencedTaskRunnerHandle::Get()->PostDelayedTask( + FROM_HERE, run_loop.QuitClosure(), + base::TimeDelta::FromMilliseconds(100)); + run_loop.Run(); + EXPECT_FALSE(expected_report.HasRequest()); + + SetBrowserClientForTesting(old_browser_client); +} + } // namespace content |