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/path_service.h" | 5 #include "base/path_service.h" |
6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
7 #include "chrome/browser/devtools/devtools_window.h" | 7 #include "chrome/browser/devtools/devtools_window.h" |
8 #include "chrome/browser/extensions/api/developer_private/developer_private_api.
h" | 8 #include "chrome/browser/extensions/api/developer_private/developer_private_api.
h" |
9 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
10 #include "chrome/browser/extensions/extension_function_test_utils.h" | 10 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 11 #include "chrome/browser/extensions/extension_tab_util.h" |
11 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
| 13 #include "content/public/browser/render_frame_host.h" |
12 #include "extensions/browser/app_window/app_window.h" | 14 #include "extensions/browser/app_window/app_window.h" |
13 #include "extensions/browser/app_window/app_window_registry.h" | 15 #include "extensions/browser/app_window/app_window_registry.h" |
14 | 16 |
15 namespace extensions { | 17 namespace extensions { |
16 | 18 |
17 using DeveloperPrivateApiTest = ExtensionApiTest; | 19 using DeveloperPrivateApiTest = ExtensionApiTest; |
18 | 20 |
19 IN_PROC_BROWSER_TEST_F(DeveloperPrivateApiTest, Basics) { | 21 IN_PROC_BROWSER_TEST_F(DeveloperPrivateApiTest, Basics) { |
20 // Load up some extensions so that we can query their info and adjust their | 22 // Load up some extensions so that we can query their info and adjust their |
21 // setings in the API test. | 23 // setings in the API test. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 browser(), extension_function_test_utils::NONE); | 76 browser(), extension_function_test_utils::NONE); |
75 | 77 |
76 // Verify that dev tools opened. | 78 // Verify that dev tools opened. |
77 std::list<AppWindow*> app_windows = | 79 std::list<AppWindow*> app_windows = |
78 AppWindowRegistry::Get(profile())->GetAppWindowsForApp(app->id()); | 80 AppWindowRegistry::Get(profile())->GetAppWindowsForApp(app->id()); |
79 ASSERT_EQ(1u, app_windows.size()); | 81 ASSERT_EQ(1u, app_windows.size()); |
80 EXPECT_TRUE(DevToolsWindow::GetInstanceForInspectedWebContents( | 82 EXPECT_TRUE(DevToolsWindow::GetInstanceForInspectedWebContents( |
81 (*app_windows.begin())->web_contents())); | 83 (*app_windows.begin())->web_contents())); |
82 } | 84 } |
83 | 85 |
| 86 IN_PROC_BROWSER_TEST_F(DeveloperPrivateApiTest, InspectEmbeddedOptionsPage) { |
| 87 base::FilePath dir; |
| 88 PathService::Get(chrome::DIR_TEST_DATA, &dir); |
| 89 // Load an extension that only has an embedded options_ui page. |
| 90 const Extension* extension = LoadExtension(dir.AppendASCII("extensions") |
| 91 .AppendASCII("delayed_install") |
| 92 .AppendASCII("v1")); |
| 93 ASSERT_TRUE(extension); |
| 94 |
| 95 // Open the embedded options page. |
| 96 ASSERT_TRUE(ExtensionTabUtil::OpenOptionsPage(extension, browser())); |
| 97 WaitForExtensionNotIdle(extension->id()); |
| 98 |
| 99 // Get the info about the extension, including the inspectable views. |
| 100 scoped_refptr<UIThreadExtensionFunction> function( |
| 101 new api::DeveloperPrivateGetExtensionInfoFunction()); |
| 102 scoped_ptr<base::Value> result( |
| 103 extension_function_test_utils::RunFunctionAndReturnSingleResult( |
| 104 function.get(), |
| 105 base::StringPrintf("[\"%s\"]", extension->id().c_str()), browser())); |
| 106 ASSERT_TRUE(result); |
| 107 scoped_ptr<api::developer_private::ExtensionInfo> info = |
| 108 api::developer_private::ExtensionInfo::FromValue(*result); |
| 109 ASSERT_TRUE(info); |
| 110 |
| 111 // The embedded options page should show up. |
| 112 ASSERT_EQ(1u, info->views.size()); |
| 113 api::developer_private::ExtensionView* view = info->views[0].get(); |
| 114 ASSERT_TRUE(view); |
| 115 ASSERT_EQ(api::developer_private::VIEW_TYPE_EXTENSION_GUEST, view->type); |
| 116 |
| 117 // Inspect the embedded options page. |
| 118 function = new api::DeveloperPrivateOpenDevToolsFunction(); |
| 119 extension_function_test_utils::RunFunction( |
| 120 function.get(), |
| 121 base::StringPrintf("[{\"renderViewId\": %d, \"renderProcessId\": %d}]", |
| 122 view->render_view_id, view->render_process_id), |
| 123 browser(), extension_function_test_utils::NONE); |
| 124 |
| 125 // Verify that dev tools opened. |
| 126 content::RenderFrameHost* rfh = content::RenderFrameHost::FromID( |
| 127 view->render_process_id, view->render_view_id); |
| 128 ASSERT_TRUE(rfh); |
| 129 content::WebContents* wc = content::WebContents::FromRenderFrameHost(rfh); |
| 130 ASSERT_TRUE(wc); |
| 131 EXPECT_TRUE(DevToolsWindow::GetInstanceForInspectedWebContents(wc)); |
| 132 } |
| 133 |
84 } // namespace extensions | 134 } // namespace extensions |
OLD | NEW |