| 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 "base/time.h" |
| 7 #include "chrome/browser/browser_process.h" | 7 #include "content/browser/content_browser_client.h" |
| 8 #include "chrome/test/base/testing_browser_process.h" | |
| 9 #include "content/browser/debugger/devtools_client_host.h" | 8 #include "content/browser/debugger/devtools_client_host.h" |
| 10 #include "content/browser/debugger/devtools_manager.h" | 9 #include "content/browser/debugger/devtools_manager.h" |
| 10 #include "content/browser/mock_content_browser_client.h" |
| 11 #include "content/browser/renderer_host/test_render_view_host.h" | 11 #include "content/browser/renderer_host/test_render_view_host.h" |
| 12 #include "content/browser/tab_contents/tab_contents_delegate.h" | 12 #include "content/browser/tab_contents/tab_contents_delegate.h" |
| 13 #include "content/browser/tab_contents/test_tab_contents.h" | 13 #include "content/browser/tab_contents/test_tab_contents.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 using base::TimeDelta; | 16 using base::TimeDelta; |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 class TestDevToolsClientHost : public DevToolsClientHost { | 20 class TestDevToolsClientHost : public DevToolsClientHost { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 } | 77 } |
| 78 | 78 |
| 79 bool renderer_unresponsive_received() const { | 79 bool renderer_unresponsive_received() const { |
| 80 return renderer_unresponsive_received_; | 80 return renderer_unresponsive_received_; |
| 81 } | 81 } |
| 82 | 82 |
| 83 private: | 83 private: |
| 84 bool renderer_unresponsive_received_; | 84 bool renderer_unresponsive_received_; |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 class DevToolsManagerTestBrowserClient |
| 88 : public content::MockContentBrowserClient { |
| 89 public: |
| 90 DevToolsManagerTestBrowserClient() { |
| 91 } |
| 92 |
| 93 virtual DevToolsManager* GetDevToolsManager() OVERRIDE { |
| 94 return &dev_tools_manager_; |
| 95 } |
| 96 |
| 97 private: |
| 98 DevToolsManager dev_tools_manager_; |
| 99 |
| 100 DISALLOW_COPY_AND_ASSIGN(DevToolsManagerTestBrowserClient); |
| 101 }; |
| 102 |
| 87 } // namespace | 103 } // namespace |
| 88 | 104 |
| 89 class DevToolsManagerTest : public RenderViewHostTestHarness { | 105 class DevToolsManagerTest : public RenderViewHostTestHarness { |
| 90 public: | 106 public: |
| 91 DevToolsManagerTest() : RenderViewHostTestHarness() { | 107 DevToolsManagerTest() : RenderViewHostTestHarness() { |
| 92 } | 108 } |
| 93 | 109 |
| 94 protected: | 110 protected: |
| 95 virtual void SetUp() { | 111 virtual void SetUp() OVERRIDE { |
| 112 original_browser_client_ = content::GetContentClient()->browser(); |
| 113 content::GetContentClient()->set_browser(&browser_client_); |
| 114 |
| 96 RenderViewHostTestHarness::SetUp(); | 115 RenderViewHostTestHarness::SetUp(); |
| 97 TestDevToolsClientHost::ResetCounters(); | 116 TestDevToolsClientHost::ResetCounters(); |
| 98 } | 117 } |
| 118 |
| 119 virtual void TearDown() OVERRIDE { |
| 120 RenderViewHostTestHarness::TearDown(); |
| 121 content::GetContentClient()->set_browser(original_browser_client_); |
| 122 } |
| 123 |
| 124 private: |
| 125 content::ContentBrowserClient* original_browser_client_; |
| 126 DevToolsManagerTestBrowserClient browser_client_; |
| 99 }; | 127 }; |
| 100 | 128 |
| 101 TEST_F(DevToolsManagerTest, OpenAndManuallyCloseDevToolsClientHost) { | 129 TEST_F(DevToolsManagerTest, OpenAndManuallyCloseDevToolsClientHost) { |
| 102 DevToolsManager manager; | 130 DevToolsManager manager; |
| 103 | 131 |
| 104 DevToolsClientHost* host = manager.GetDevToolsClientHostFor(rvh()); | 132 DevToolsClientHost* host = manager.GetDevToolsClientHostFor(rvh()); |
| 105 EXPECT_TRUE(NULL == host); | 133 EXPECT_TRUE(NULL == host); |
| 106 | 134 |
| 107 TestDevToolsClientHost client_host; | 135 TestDevToolsClientHost client_host; |
| 108 manager.RegisterDevToolsClientHostFor(rvh(), &client_host); | 136 manager.RegisterDevToolsClientHostFor(rvh(), &client_host); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 137 EXPECT_EQ(1, TestDevToolsClientHost::close_counter); | 165 EXPECT_EQ(1, TestDevToolsClientHost::close_counter); |
| 138 } | 166 } |
| 139 | 167 |
| 140 TEST_F(DevToolsManagerTest, NoUnresponsiveDialogInInspectedTab) { | 168 TEST_F(DevToolsManagerTest, NoUnresponsiveDialogInInspectedTab) { |
| 141 TestRenderViewHost* inspected_rvh = rvh(); | 169 TestRenderViewHost* inspected_rvh = rvh(); |
| 142 inspected_rvh->set_render_view_created(true); | 170 inspected_rvh->set_render_view_created(true); |
| 143 EXPECT_FALSE(contents()->delegate()); | 171 EXPECT_FALSE(contents()->delegate()); |
| 144 TestTabContentsDelegate delegate; | 172 TestTabContentsDelegate delegate; |
| 145 contents()->set_delegate(&delegate); | 173 contents()->set_delegate(&delegate); |
| 146 | 174 |
| 147 static_cast<TestingBrowserProcess*>(g_browser_process)-> | |
| 148 SetDevToolsManager(new DevToolsManager()); | |
| 149 DevToolsManager* manager = DevToolsManager::GetInstance(); | |
| 150 ASSERT_TRUE(manager); | |
| 151 | |
| 152 TestDevToolsClientHost client_host; | 175 TestDevToolsClientHost client_host; |
| 153 manager->RegisterDevToolsClientHostFor(inspected_rvh, &client_host); | 176 content::GetContentClient()->browser()->GetDevToolsManager()-> |
| 177 RegisterDevToolsClientHostFor(inspected_rvh, &client_host); |
| 154 | 178 |
| 155 // Start with a short timeout. | 179 // Start with a short timeout. |
| 156 inspected_rvh->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); | 180 inspected_rvh->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); |
| 157 // Wait long enough for first timeout and see if it fired. | 181 // Wait long enough for first timeout and see if it fired. |
| 158 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 182 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 159 new MessageLoop::QuitTask(), 10); | 183 new MessageLoop::QuitTask(), 10); |
| 160 MessageLoop::current()->Run(); | 184 MessageLoop::current()->Run(); |
| 161 EXPECT_FALSE(delegate.renderer_unresponsive_received()); | 185 EXPECT_FALSE(delegate.renderer_unresponsive_received()); |
| 162 | 186 |
| 163 // Now close devtools and check that the notification is delivered. | 187 // Now close devtools and check that the notification is delivered. |
| 164 client_host.Close(); | 188 client_host.Close(); |
| 165 // Start with a short timeout. | 189 // Start with a short timeout. |
| 166 inspected_rvh->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); | 190 inspected_rvh->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); |
| 167 // Wait long enough for first timeout and see if it fired. | 191 // Wait long enough for first timeout and see if it fired. |
| 168 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 192 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 169 new MessageLoop::QuitTask(), 10); | 193 new MessageLoop::QuitTask(), 10); |
| 170 MessageLoop::current()->Run(); | 194 MessageLoop::current()->Run(); |
| 171 EXPECT_TRUE(delegate.renderer_unresponsive_received()); | 195 EXPECT_TRUE(delegate.renderer_unresponsive_received()); |
| 172 | 196 |
| 173 contents()->set_delegate(NULL); | 197 contents()->set_delegate(NULL); |
| 174 } | 198 } |
| OLD | NEW |