OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 "chrome/test/base/tracing.h" |
| 6 |
| 7 #include "base/debug/trace_event.h" |
| 8 #include "base/message_loop.h" |
| 9 #include "base/run_loop.h" |
| 10 #include "chrome/test/base/in_process_browser_test.h" |
| 11 #include "chrome/test/base/ui_test_utils.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 namespace { |
| 15 |
| 16 using tracing::BeginTracingWithWatch; |
| 17 using tracing::WaitForWatchEvent; |
| 18 using tracing::EndTracing; |
| 19 |
| 20 const char* g_category = "test_tracing"; |
| 21 const char* g_event = "TheEvent"; |
| 22 |
| 23 class TracingBrowserTest : public InProcessBrowserTest { |
| 24 }; |
| 25 |
| 26 void AddEvents(int num) { |
| 27 for (int i = 0; i < num; ++i) |
| 28 TRACE_EVENT_INSTANT0(g_category, g_event); |
| 29 } |
| 30 |
| 31 IN_PROC_BROWSER_TEST_F(TracingBrowserTest, BeginTracingWithWatch) { |
| 32 base::TimeDelta no_timeout; |
| 33 base::TimeDelta short_timeout = base::TimeDelta::FromMilliseconds(5); |
| 34 std::string json_events; |
| 35 |
| 36 // One event before wait. |
| 37 ASSERT_TRUE(BeginTracingWithWatch(g_category, g_category, g_event, 1)); |
| 38 AddEvents(1); |
| 39 EXPECT_TRUE(WaitForWatchEvent(no_timeout)); |
| 40 ASSERT_TRUE(EndTracing(&json_events)); |
| 41 |
| 42 // One event after wait. |
| 43 ASSERT_TRUE(BeginTracingWithWatch(g_category, g_category, g_event, 1)); |
| 44 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&AddEvents, 1)); |
| 45 EXPECT_TRUE(WaitForWatchEvent(no_timeout)); |
| 46 ASSERT_TRUE(EndTracing(&json_events)); |
| 47 |
| 48 // Not enough events timeout. |
| 49 ASSERT_TRUE(BeginTracingWithWatch(g_category, g_category, g_event, 2)); |
| 50 AddEvents(1); |
| 51 EXPECT_FALSE(WaitForWatchEvent(short_timeout)); |
| 52 ASSERT_TRUE(EndTracing(&json_events)); |
| 53 |
| 54 // Multi event before wait. |
| 55 ASSERT_TRUE(BeginTracingWithWatch(g_category, g_category, g_event, 5)); |
| 56 AddEvents(5); |
| 57 EXPECT_TRUE(WaitForWatchEvent(no_timeout)); |
| 58 ASSERT_TRUE(EndTracing(&json_events)); |
| 59 |
| 60 // Multi event after wait. |
| 61 ASSERT_TRUE(BeginTracingWithWatch(g_category, g_category, g_event, 5)); |
| 62 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&AddEvents, 5)); |
| 63 EXPECT_TRUE(WaitForWatchEvent(no_timeout)); |
| 64 ASSERT_TRUE(EndTracing(&json_events)); |
| 65 |
| 66 // Child process events from same process. |
| 67 GURL url1("chrome://tracing"); |
| 68 ASSERT_TRUE(BeginTracingWithWatch(g_category, g_category, |
| 69 "RenderViewImpl::OnNavigate", 2)); |
| 70 ui_test_utils::NavigateToURL(browser(), url1); |
| 71 ui_test_utils::NavigateToURL(browser(), url1); |
| 72 EXPECT_TRUE(WaitForWatchEvent(no_timeout)); |
| 73 ASSERT_TRUE(EndTracing(&json_events)); |
| 74 |
| 75 // Child process events from different processes. |
| 76 GURL url2("about:blank"); |
| 77 ASSERT_TRUE(BeginTracingWithWatch(g_category, g_category, |
| 78 "RenderViewImpl::OnNavigate", 2)); |
| 79 // Open two tabs to different URLs to encourage two separate renderer |
| 80 // processes. Each will fire an event that will be counted towards the total. |
| 81 ui_test_utils::NavigateToURL(browser(), url1); |
| 82 ui_test_utils::NavigateToURLWithDisposition(browser(), url2, |
| 83 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 84 EXPECT_TRUE(WaitForWatchEvent(no_timeout)); |
| 85 ASSERT_TRUE(EndTracing(&json_events)); |
| 86 } |
| 87 |
| 88 } // namespace |
OLD | NEW |