OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <string> |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/macros.h" |
| 9 #include "base/test/histogram_tester.h" |
| 10 #include "chrome/test/base/in_process_browser_test.h" |
| 11 #include "chrome/test/base/ui_test_utils.h" |
| 12 #include "content/public/common/content_switches.h" |
| 13 #include "content/public/test/browser_test.h" |
| 14 #include "content/public/test/browser_test_utils.h" |
| 15 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "url/gurl.h" |
| 18 |
| 19 const char kAdsMetricsFeature[] = "AdsMetrics"; |
| 20 |
| 21 class AdsPageLoadMetricsObserverBrowserTest : public InProcessBrowserTest { |
| 22 public: |
| 23 AdsPageLoadMetricsObserverBrowserTest() { |
| 24 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 25 cmd_line->AppendSwitchASCII(switches::kEnableFeatures, kAdsMetricsFeature); |
| 26 } |
| 27 ~AdsPageLoadMetricsObserverBrowserTest() override {} |
| 28 |
| 29 void SetUpOnMainThread() override { |
| 30 ASSERT_TRUE(embedded_test_server()->Start()); |
| 31 InProcessBrowserTest::SetUpOnMainThread(); |
| 32 } |
| 33 |
| 34 private: |
| 35 DISALLOW_COPY_AND_ASSIGN(AdsPageLoadMetricsObserverBrowserTest); |
| 36 }; |
| 37 |
| 38 // Test that a subframe that aborts (due to doc.write) doesn't cause a crash |
| 39 // if it continues to load resources. |
| 40 IN_PROC_BROWSER_TEST_F(AdsPageLoadMetricsObserverBrowserTest, |
| 41 DocOverwritesNavigation) { |
| 42 content::DOMMessageQueue msg_queue; |
| 43 |
| 44 base::HistogramTester histogram_tester; |
| 45 |
| 46 ui_test_utils::NavigateToURL( |
| 47 browser(), embedded_test_server()->GetURL( |
| 48 "/ads_observer/docwrite_provisional_frame.html")); |
| 49 std::string status; |
| 50 EXPECT_TRUE(msg_queue.WaitForMessage(&status)); |
| 51 EXPECT_EQ("\"loaded\"", status); |
| 52 |
| 53 // Navigate away to force the histogram recording. |
| 54 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); |
| 55 |
| 56 histogram_tester.ExpectUniqueSample( |
| 57 "PageLoad.Clients.Ads.Google.FrameCounts.AnyParentFrame.AdFrames", 1, 1); |
| 58 histogram_tester.ExpectUniqueSample( |
| 59 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.Total", |
| 60 0 /* < 1 KB */, 1); |
| 61 } |
OLD | NEW |