OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/time.h" |
6 #include "content/browser/debugger/devtools_client_host.h" | 7 #include "content/browser/debugger/devtools_client_host.h" |
7 #include "content/browser/debugger/devtools_manager.h" | 8 #include "content/browser/debugger/devtools_manager.h" |
8 #include "content/browser/renderer_host/test_render_view_host.h" | 9 #include "content/browser/renderer_host/test_render_view_host.h" |
| 10 #include "content/browser/tab_contents/tab_contents_delegate.h" |
| 11 #include "content/browser/tab_contents/test_tab_contents.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
10 | 13 |
| 14 using base::TimeDelta; |
| 15 |
11 namespace { | 16 namespace { |
12 | 17 |
13 class TestDevToolsClientHost : public DevToolsClientHost { | 18 class TestDevToolsClientHost : public DevToolsClientHost { |
14 public: | 19 public: |
15 TestDevToolsClientHost() | 20 TestDevToolsClientHost() |
16 : last_sent_message(NULL), | 21 : last_sent_message(NULL), |
17 closed_(false) { | 22 closed_(false) { |
18 } | 23 } |
19 | 24 |
20 virtual ~TestDevToolsClientHost() { | 25 virtual ~TestDevToolsClientHost() { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 private: | 57 private: |
53 bool closed_; | 58 bool closed_; |
54 | 59 |
55 virtual void FrameNavigating(const std::string& url) {} | 60 virtual void FrameNavigating(const std::string& url) {} |
56 | 61 |
57 DISALLOW_COPY_AND_ASSIGN(TestDevToolsClientHost); | 62 DISALLOW_COPY_AND_ASSIGN(TestDevToolsClientHost); |
58 }; | 63 }; |
59 | 64 |
60 int TestDevToolsClientHost::close_counter = 0; | 65 int TestDevToolsClientHost::close_counter = 0; |
61 | 66 |
| 67 |
| 68 class TestTabContentsDelegate : public TabContentsDelegate { |
| 69 public: |
| 70 TestTabContentsDelegate() : renderer_unresponsive_received_(false) {} |
| 71 |
| 72 // Notification that the tab is hung. |
| 73 virtual void RendererUnresponsive(TabContents* source) { |
| 74 renderer_unresponsive_received_ = true; |
| 75 } |
| 76 |
| 77 bool renderer_unresponsive_received() const { |
| 78 return renderer_unresponsive_received_; |
| 79 } |
| 80 |
| 81 private: |
| 82 bool renderer_unresponsive_received_; |
| 83 }; |
| 84 |
62 } // namespace | 85 } // namespace |
63 | 86 |
64 class DevToolsManagerTest : public RenderViewHostTestHarness { | 87 class DevToolsManagerTest : public RenderViewHostTestHarness { |
65 public: | 88 public: |
66 DevToolsManagerTest() : RenderViewHostTestHarness() { | 89 DevToolsManagerTest() : RenderViewHostTestHarness() { |
67 } | 90 } |
68 | 91 |
69 protected: | 92 protected: |
70 virtual void SetUp() { | 93 virtual void SetUp() { |
71 RenderViewHostTestHarness::SetUp(); | 94 RenderViewHostTestHarness::SetUp(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 manager.RegisterDevToolsClientHostFor(rvh(), &client_host); | 127 manager.RegisterDevToolsClientHostFor(rvh(), &client_host); |
105 EXPECT_EQ(0, TestDevToolsClientHost::close_counter); | 128 EXPECT_EQ(0, TestDevToolsClientHost::close_counter); |
106 | 129 |
107 IPC::Message m; | 130 IPC::Message m; |
108 manager.ForwardToDevToolsClient(rvh(), m); | 131 manager.ForwardToDevToolsClient(rvh(), m); |
109 EXPECT_TRUE(&m == client_host.last_sent_message); | 132 EXPECT_TRUE(&m == client_host.last_sent_message); |
110 | 133 |
111 client_host.Close(); | 134 client_host.Close(); |
112 EXPECT_EQ(1, TestDevToolsClientHost::close_counter); | 135 EXPECT_EQ(1, TestDevToolsClientHost::close_counter); |
113 } | 136 } |
| 137 |
| 138 TEST_F(DevToolsManagerTest, NoUnresponsiveDialogInInspectedTab) { |
| 139 TestRenderViewHost* inspected_rvh = rvh(); |
| 140 inspected_rvh->set_render_view_created(true); |
| 141 EXPECT_FALSE(contents()->delegate()); |
| 142 TestTabContentsDelegate delegate; |
| 143 contents()->set_delegate(&delegate); |
| 144 |
| 145 testing_browser_process_.get()->SetDevToolsManager(new DevToolsManager()); |
| 146 DevToolsManager* manager = DevToolsManager::GetInstance(); |
| 147 ASSERT_TRUE(manager); |
| 148 |
| 149 TestDevToolsClientHost client_host; |
| 150 manager->RegisterDevToolsClientHostFor(inspected_rvh, &client_host); |
| 151 |
| 152 // Start with a short timeout. |
| 153 inspected_rvh->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); |
| 154 // Wait long enough for first timeout and see if it fired. |
| 155 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 156 new MessageLoop::QuitTask(), 10); |
| 157 MessageLoop::current()->Run(); |
| 158 EXPECT_FALSE(delegate.renderer_unresponsive_received()); |
| 159 |
| 160 // Now close devtools and check that the notification is delivered. |
| 161 client_host.Close(); |
| 162 // Start with a short timeout. |
| 163 inspected_rvh->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); |
| 164 // Wait long enough for first timeout and see if it fired. |
| 165 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 166 new MessageLoop::QuitTask(), 10); |
| 167 MessageLoop::current()->Run(); |
| 168 EXPECT_TRUE(delegate.renderer_unresponsive_received()); |
| 169 |
| 170 contents()->set_delegate(NULL); |
| 171 } |
OLD | NEW |