Index: content/browser/tracing/background_tracing_manager_browsertest.cc |
diff --git a/content/browser/tracing/background_tracing_manager_browsertest.cc b/content/browser/tracing/background_tracing_manager_browsertest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6ab63d5a72c2243e577b3e716216feafbc617a28 |
--- /dev/null |
+++ b/content/browser/tracing/background_tracing_manager_browsertest.cc |
@@ -0,0 +1,170 @@ |
+// Copyright (c) 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/bind.h" |
+#include "content/browser/tracing/background_tracing_endpoint.h" |
+#include "content/browser/tracing/background_tracing_manager.h" |
+#include "content/browser/tracing/background_tracing_scenario.h" |
+#include "content/browser/web_contents/web_contents_impl.h" |
+#include "content/public/browser/web_contents_observer.h" |
+#include "content/public/common/content_switches.h" |
+#include "content/public/test/browser_test_utils.h" |
+#include "content/public/test/content_browser_test.h" |
+#include "content/public/test/content_browser_test_utils.h" |
+#include "content/public/test/test_utils.h" |
+#include "content/shell/browser/shell.h" |
+#include "content/shell/browser/shell_resource_dispatcher_host_delegate.h" |
oystein (OOO til 10th of July)
2015/04/21 17:31:44
Are all of these includes used here?
|
+#include "net/test/embedded_test_server/embedded_test_server.h" |
+#include "net/url_request/url_request.h" |
+ |
+namespace content { |
+ |
+class BackgroundTracingManagerBrowserTest : public ContentBrowserTest { |
+ public: |
+ BackgroundTracingManagerBrowserTest() {} |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(BackgroundTracingManagerBrowserTest); |
+}; |
+ |
+class BackgroundTracingManagerBrowserTestEndpoint |
+ : public BackgroundTracingEndpoint { |
+ public: |
+ BackgroundTracingManagerBrowserTestEndpoint(const base::Closure& callback) |
+ : callback_(callback), receive_count_(0) {} |
+ |
+ void ReceiveTraceFinalContents(const std::string& file_contents) override { |
+ receive_count_ += 1; |
+ done_callback_.Run(); |
+ callback_.Run(); |
+ } |
+ |
+ int get_receive_count() const { return receive_count_; } |
+ |
+ private: |
+ ~BackgroundTracingManagerBrowserTestEndpoint() override {} |
+ |
+ base::Closure callback_; |
+ int receive_count_; |
+}; |
+ |
+class BackgroundTracingManagerBrowserTestScenario |
+ : public BackgroundTracingScenario { |
+ public: |
+ BackgroundTracingManagerBrowserTestScenario( |
+ scoped_refptr<BackgroundTracingManagerBrowserTestEndpoint> e) |
+ : BackgroundTracingScenario(e) {} |
+ |
+ protected: |
+ ~BackgroundTracingManagerBrowserTestScenario() override {} |
+}; |
+ |
+void StartedFinalizingCallback(base::Closure callback, |
+ bool expected, |
+ bool value) { |
+ EXPECT_EQ(expected, value); |
+ if (!callback.is_null()) |
+ callback.Run(); |
+} |
+ |
+// This tests that the endpoint receives the final trace data. |
+IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest, |
+ ReceiveTraceFinalContentsOnTrigger) { |
+ { |
+ base::RunLoop run_loop; |
+ scoped_refptr<BackgroundTracingManagerBrowserTestEndpoint> endpoint = |
+ new BackgroundTracingManagerBrowserTestEndpoint(run_loop.QuitClosure()); |
+ scoped_refptr<BackgroundTracingManagerBrowserTestScenario> scenario = |
+ new BackgroundTracingManagerBrowserTestScenario(endpoint); |
+ |
+ EXPECT_FALSE( |
+ BackgroundTracingManager::GetInstance()->is_recording_for_testing()); |
+ |
+ BackgroundTracingManager::GetInstance()->SetActiveScenario(scenario); |
+ |
+ EXPECT_TRUE( |
+ BackgroundTracingManager::GetInstance()->is_recording_for_testing()); |
+ |
+ BackgroundTracingManager::GetInstance()->TryFinalizingBackgroundTracing( |
+ base::Bind(&StartedFinalizingCallback, base::Closure(), true)); |
+ |
+ EXPECT_TRUE( |
+ BackgroundTracingManager::GetInstance()->is_gathering_for_testing()); |
+ |
+ run_loop.Run(); |
+ |
+ EXPECT_FALSE( |
+ BackgroundTracingManager::GetInstance()->is_gathering_for_testing()); |
+ EXPECT_TRUE(endpoint->get_receive_count() == 1); |
+ } |
+} |
+ |
+// This tests trigger more than once still only gathers once. |
+IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest, |
+ MultipleTriggersOnlyGatherOnce) { |
+ { |
+ base::RunLoop run_loop; |
+ scoped_refptr<BackgroundTracingManagerBrowserTestEndpoint> endpoint = |
+ new BackgroundTracingManagerBrowserTestEndpoint(run_loop.QuitClosure()); |
+ scoped_refptr<BackgroundTracingManagerBrowserTestScenario> scenario = |
+ new BackgroundTracingManagerBrowserTestScenario(endpoint); |
+ |
+ EXPECT_FALSE( |
+ BackgroundTracingManager::GetInstance()->is_recording_for_testing()); |
+ |
+ BackgroundTracingManager::GetInstance()->SetActiveScenario(scenario); |
+ |
+ EXPECT_TRUE( |
+ BackgroundTracingManager::GetInstance()->is_recording_for_testing()); |
+ |
+ BackgroundTracingManager::GetInstance()->TryFinalizingBackgroundTracing( |
+ base::Bind(&StartedFinalizingCallback, base::Closure(), true)); |
+ |
+ EXPECT_TRUE( |
+ BackgroundTracingManager::GetInstance()->is_gathering_for_testing()); |
+ |
+ BackgroundTracingManager::GetInstance()->TryFinalizingBackgroundTracing( |
+ base::Bind(&StartedFinalizingCallback, base::Closure(), false)); |
+ |
+ run_loop.Run(); |
+ |
+ EXPECT_FALSE( |
+ BackgroundTracingManager::GetInstance()->is_gathering_for_testing()); |
+ EXPECT_TRUE(endpoint->get_receive_count() == 1); |
+ } |
+} |
+ |
+// This tests that you can't trigger without a scenario set. |
+IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest, |
+ CannotTriggerWithoutScenarioSet) { |
+ { |
+ base::RunLoop run_loop; |
+ |
+ EXPECT_FALSE( |
+ BackgroundTracingManager::GetInstance()->is_recording_for_testing()); |
+ EXPECT_FALSE( |
+ BackgroundTracingManager::GetInstance()->is_gathering_for_testing()); |
+ |
+ printf("trying\n"); |
oystein (OOO til 10th of July)
2015/04/21 17:31:44
nit: remove
|
+ BackgroundTracingManager::GetInstance()->TryFinalizingBackgroundTracing( |
+ base::Bind(&StartedFinalizingCallback, run_loop.QuitClosure(), false)); |
+ |
+ run_loop.Run(); |
+ printf("checking\n"); |
oystein (OOO til 10th of July)
2015/04/21 17:31:44
nit: same
|
+ |
+ EXPECT_FALSE( |
+ BackgroundTracingManager::GetInstance()->is_recording_for_testing()); |
+ EXPECT_FALSE( |
+ BackgroundTracingManager::GetInstance()->is_gathering_for_testing()); |
+ } |
+} |
+ |
+// This tests triggering with a null callback. |
+IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest, |
+ TriggerWithNullCallback) { |
+ BackgroundTracingManager::GetInstance()->TryFinalizingBackgroundTracing( |
+ BackgroundTracingManager::StartedFinalizingCallback()); |
+} |
+ |
+} // namespace content |