Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
| 6 #include "base/stringprintf.h" | 6 #include "base/stringprintf.h" |
| 7 #include "chrome/browser/extensions/extension_devtools_browsertest.h" | 7 #include "chrome/browser/extensions/extension_devtools_browsertest.h" |
| 8 #include "chrome/browser/extensions/extension_error_reporter.h" | 8 #include "chrome/browser/extensions/extension_error_reporter.h" |
| 9 #include "chrome/browser/extensions/extension_host.h" | 9 #include "chrome/browser/extensions/extension_host.h" |
| 10 #include "chrome/browser/extensions/extension_process_manager.h" | 10 #include "chrome/browser/extensions/extension_process_manager.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 #include "content/public/browser/render_view_host.h" | 22 #include "content/public/browser/render_view_host.h" |
| 23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 24 #include "net/base/net_util.h" | 24 #include "net/base/net_util.h" |
| 25 | 25 |
| 26 using content::DevToolsAgentHost; | 26 using content::DevToolsAgentHost; |
| 27 using content::DevToolsAgentHostRegistry; | 27 using content::DevToolsAgentHostRegistry; |
| 28 using content::DevToolsClientHost; | 28 using content::DevToolsClientHost; |
| 29 using content::DevToolsManager; | 29 using content::DevToolsManager; |
| 30 using content::WebContents; | 30 using content::WebContents; |
| 31 | 31 |
| 32 // Looks for an ExtensionHost whose URL has the given path component (including | 32 // Looks for an background ExtensionHost whose URL has the given path component |
|
Charlie Reis
2012/04/25 00:04:13
nit: a background
| |
| 33 // leading slash). Also verifies that the expected number of hosts are loaded. | 33 // (including leading slash). Also verifies that the expected number of hosts |
| 34 static ExtensionHost* FindHostWithPath(ExtensionProcessManager* manager, | 34 // are loaded. |
| 35 const std::string& path, | 35 static ExtensionHost* FindBackgroundHostWithPath( |
| 36 int expected_hosts) { | 36 ExtensionProcessManager* manager, |
| 37 const std::string& path, | |
| 38 int expected_hosts) { | |
| 37 ExtensionHost* host = NULL; | 39 ExtensionHost* host = NULL; |
| 38 int num_hosts = 0; | 40 int num_hosts = 0; |
| 39 for (ExtensionProcessManager::const_iterator iter = manager->begin(); | 41 ExtensionProcessManager::ExtensionHostSet background_hosts = |
| 40 iter != manager->end(); ++iter) { | 42 manager->background_hosts(); |
| 43 for (ExtensionProcessManager::const_iterator iter = background_hosts.begin(); | |
| 44 iter != background_hosts.end(); ++iter) { | |
| 41 if ((*iter)->GetURL().path() == path) { | 45 if ((*iter)->GetURL().path() == path) { |
| 42 EXPECT_FALSE(host); | 46 EXPECT_FALSE(host); |
| 43 host = *iter; | 47 host = *iter; |
| 44 } | 48 } |
| 45 num_hosts++; | 49 num_hosts++; |
| 46 } | 50 } |
| 47 EXPECT_EQ(expected_hosts, num_hosts); | 51 EXPECT_EQ(expected_hosts, num_hosts); |
| 48 EXPECT_TRUE(host); | 52 EXPECT_TRUE(host); |
| 49 return host; | 53 return host; |
| 50 } | 54 } |
| 51 | 55 |
| 52 // Tests for the experimental timeline extensions API. | 56 // Tests for the experimental timeline extensions API. |
| 53 IN_PROC_BROWSER_TEST_F(ExtensionDevToolsBrowserTest, TimelineApi) { | 57 IN_PROC_BROWSER_TEST_F(ExtensionDevToolsBrowserTest, TimelineApi) { |
| 54 ASSERT_TRUE(LoadExtension( | 58 ASSERT_TRUE(LoadExtension( |
| 55 test_data_dir_.AppendASCII("devtools").AppendASCII("timeline_api"))); | 59 test_data_dir_.AppendASCII("devtools").AppendASCII("timeline_api"))); |
| 56 | 60 |
| 57 // Get the ExtensionHost that is hosting our background page. | 61 // Get the ExtensionHost that is hosting our background page. |
| 58 ExtensionProcessManager* manager = | 62 ExtensionProcessManager* manager = |
| 59 browser()->profile()->GetExtensionProcessManager(); | 63 browser()->profile()->GetExtensionProcessManager(); |
| 60 ExtensionHost* host = FindHostWithPath(manager, "/background.html", 1); | 64 ExtensionHost* host = FindBackgroundHostWithPath(manager, |
| 65 "/background.html", 1); | |
| 61 | 66 |
| 62 // Grab a handle to the DevToolsManager so we can forward messages to it. | 67 // Grab a handle to the DevToolsManager so we can forward messages to it. |
| 63 DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); | 68 DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); |
| 64 | 69 |
| 65 // Grab the tab_id of whatever tab happens to be first. | 70 // Grab the tab_id of whatever tab happens to be first. |
| 66 WebContents* web_contents = browser()->GetWebContentsAt(0); | 71 WebContents* web_contents = browser()->GetWebContentsAt(0); |
| 67 ASSERT_TRUE(web_contents); | 72 ASSERT_TRUE(web_contents); |
| 68 int tab_id = ExtensionTabUtil::GetTabId(web_contents); | 73 int tab_id = ExtensionTabUtil::GetTabId(web_contents); |
| 69 | 74 |
| 70 // Test setup. | 75 // Test setup. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 | 108 |
| 104 | 109 |
| 105 // Tests that ref counting of listeners from multiple processes works. | 110 // Tests that ref counting of listeners from multiple processes works. |
| 106 IN_PROC_BROWSER_TEST_F(ExtensionDevToolsBrowserTest, ProcessRefCounting) { | 111 IN_PROC_BROWSER_TEST_F(ExtensionDevToolsBrowserTest, ProcessRefCounting) { |
| 107 ASSERT_TRUE(LoadExtension( | 112 ASSERT_TRUE(LoadExtension( |
| 108 test_data_dir_.AppendASCII("devtools").AppendASCII("timeline_api"))); | 113 test_data_dir_.AppendASCII("devtools").AppendASCII("timeline_api"))); |
| 109 | 114 |
| 110 // Get the ExtensionHost that is hosting our background page. | 115 // Get the ExtensionHost that is hosting our background page. |
| 111 ExtensionProcessManager* manager = | 116 ExtensionProcessManager* manager = |
| 112 browser()->profile()->GetExtensionProcessManager(); | 117 browser()->profile()->GetExtensionProcessManager(); |
| 113 ExtensionHost* host_one = FindHostWithPath(manager, "/background.html", 1); | 118 ExtensionHost* host_one = FindBackgroundHostWithPath(manager, |
| 119 "/background.html", 1); | |
| 114 | 120 |
| 115 ASSERT_TRUE(LoadExtension( | 121 ASSERT_TRUE(LoadExtension( |
| 116 test_data_dir_.AppendASCII("devtools").AppendASCII("timeline_api_two"))); | 122 test_data_dir_.AppendASCII("devtools").AppendASCII("timeline_api_two"))); |
| 117 ExtensionHost* host_two = FindHostWithPath(manager, | 123 ExtensionHost* host_two = FindBackgroundHostWithPath(manager, |
| 118 "/background_two.html", 2); | 124 "/background_two.html", |
| 125 2); | |
| 119 | 126 |
| 120 DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); | 127 DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); |
| 121 | 128 |
| 122 // Grab the tab_id of whatever tab happens to be first. | 129 // Grab the tab_id of whatever tab happens to be first. |
| 123 WebContents* web_contents = browser()->GetWebContentsAt(0); | 130 WebContents* web_contents = browser()->GetWebContentsAt(0); |
| 124 ASSERT_TRUE(web_contents); | 131 ASSERT_TRUE(web_contents); |
| 125 int tab_id = ExtensionTabUtil::GetTabId(web_contents); | 132 int tab_id = ExtensionTabUtil::GetTabId(web_contents); |
| 126 | 133 |
| 127 // Test setup. | 134 // Test setup. |
| 128 bool result = false; | 135 bool result = false; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 158 // Removing the listeners from the second extension should tear the bridge | 165 // Removing the listeners from the second extension should tear the bridge |
| 159 // down. | 166 // down. |
| 160 result = false; | 167 result = false; |
| 161 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 168 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 162 host_two->render_view_host(), L"", L"unregisterListeners()", &result)); | 169 host_two->render_view_host(), L"", L"unregisterListeners()", &result)); |
| 163 EXPECT_TRUE(result); | 170 EXPECT_TRUE(result); |
| 164 ASSERT_FALSE(devtools_manager->GetDevToolsClientHostFor( | 171 ASSERT_FALSE(devtools_manager->GetDevToolsClientHostFor( |
| 165 DevToolsAgentHostRegistry::GetDevToolsAgentHost( | 172 DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
| 166 web_contents->GetRenderViewHost()))); | 173 web_contents->GetRenderViewHost()))); |
| 167 } | 174 } |
| OLD | NEW |