Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Unified Diff: chrome/test/base/tracing_browsertest.cc

Issue 10837082: implement SetWatchEvent and WaitForEvent for trace-based-tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update / merge -- no change Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/base/tracing.cc ('k') | content/browser/trace_controller_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/base/tracing_browsertest.cc
diff --git a/chrome/test/base/tracing_browsertest.cc b/chrome/test/base/tracing_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5b1b284225b384950d45ac184e0751f132fceec6
--- /dev/null
+++ b/chrome/test/base/tracing_browsertest.cc
@@ -0,0 +1,88 @@
+// Copyright (c) 2012 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 "chrome/test/base/tracing.h"
+
+#include "base/debug/trace_event.h"
+#include "base/message_loop.h"
+#include "base/run_loop.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+using tracing::BeginTracingWithWatch;
+using tracing::WaitForWatchEvent;
+using tracing::EndTracing;
+
+const char* g_category = "test_tracing";
+const char* g_event = "TheEvent";
+
+class TracingBrowserTest : public InProcessBrowserTest {
+};
+
+void AddEvents(int num) {
+ for (int i = 0; i < num; ++i)
+ TRACE_EVENT_INSTANT0(g_category, g_event);
+}
+
+IN_PROC_BROWSER_TEST_F(TracingBrowserTest, BeginTracingWithWatch) {
+ base::TimeDelta no_timeout;
+ base::TimeDelta short_timeout = base::TimeDelta::FromMilliseconds(5);
+ std::string json_events;
+
+ // One event before wait.
+ ASSERT_TRUE(BeginTracingWithWatch(g_category, g_category, g_event, 1));
+ AddEvents(1);
+ EXPECT_TRUE(WaitForWatchEvent(no_timeout));
+ ASSERT_TRUE(EndTracing(&json_events));
+
+ // One event after wait.
+ ASSERT_TRUE(BeginTracingWithWatch(g_category, g_category, g_event, 1));
+ MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&AddEvents, 1));
+ EXPECT_TRUE(WaitForWatchEvent(no_timeout));
+ ASSERT_TRUE(EndTracing(&json_events));
+
+ // Not enough events timeout.
+ ASSERT_TRUE(BeginTracingWithWatch(g_category, g_category, g_event, 2));
+ AddEvents(1);
+ EXPECT_FALSE(WaitForWatchEvent(short_timeout));
+ ASSERT_TRUE(EndTracing(&json_events));
+
+ // Multi event before wait.
+ ASSERT_TRUE(BeginTracingWithWatch(g_category, g_category, g_event, 5));
+ AddEvents(5);
+ EXPECT_TRUE(WaitForWatchEvent(no_timeout));
+ ASSERT_TRUE(EndTracing(&json_events));
+
+ // Multi event after wait.
+ ASSERT_TRUE(BeginTracingWithWatch(g_category, g_category, g_event, 5));
+ MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&AddEvents, 5));
+ EXPECT_TRUE(WaitForWatchEvent(no_timeout));
+ ASSERT_TRUE(EndTracing(&json_events));
+
+ // Child process events from same process.
+ GURL url1("chrome://tracing");
+ ASSERT_TRUE(BeginTracingWithWatch(g_category, g_category,
+ "RenderViewImpl::OnNavigate", 2));
+ ui_test_utils::NavigateToURL(browser(), url1);
+ ui_test_utils::NavigateToURL(browser(), url1);
+ EXPECT_TRUE(WaitForWatchEvent(no_timeout));
+ ASSERT_TRUE(EndTracing(&json_events));
+
+ // Child process events from different processes.
+ GURL url2("about:blank");
+ ASSERT_TRUE(BeginTracingWithWatch(g_category, g_category,
+ "RenderViewImpl::OnNavigate", 2));
+ // Open two tabs to different URLs to encourage two separate renderer
+ // processes. Each will fire an event that will be counted towards the total.
+ ui_test_utils::NavigateToURL(browser(), url1);
+ ui_test_utils::NavigateToURLWithDisposition(browser(), url2,
+ NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
+ EXPECT_TRUE(WaitForWatchEvent(no_timeout));
+ ASSERT_TRUE(EndTracing(&json_events));
+}
+
+} // namespace
« no previous file with comments | « chrome/test/base/tracing.cc ('k') | content/browser/trace_controller_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698