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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/cancelable_callback.h" | 10 #include "base/cancelable_callback.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 #include "chrome/browser/lifetime/application_lifetime.h" | 35 #include "chrome/browser/lifetime/application_lifetime.h" |
| 36 #include "chrome/browser/profiles/profile.h" | 36 #include "chrome/browser/profiles/profile.h" |
| 37 #include "chrome/browser/ui/browser.h" | 37 #include "chrome/browser/ui/browser.h" |
| 38 #include "chrome/browser/ui/browser_commands.h" | 38 #include "chrome/browser/ui/browser_commands.h" |
| 39 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 39 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 40 #include "chrome/common/chrome_paths.h" | 40 #include "chrome/common/chrome_paths.h" |
| 41 #include "chrome/common/chrome_switches.h" | 41 #include "chrome/common/chrome_switches.h" |
| 42 #include "chrome/common/pref_names.h" | 42 #include "chrome/common/pref_names.h" |
| 43 #include "chrome/common/url_constants.h" | 43 #include "chrome/common/url_constants.h" |
| 44 #include "chrome/test/base/in_process_browser_test.h" | 44 #include "chrome/test/base/in_process_browser_test.h" |
| 45 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" | |
| 45 #include "chrome/test/base/ui_test_utils.h" | 46 #include "chrome/test/base/ui_test_utils.h" |
| 46 #include "components/app_modal/javascript_app_modal_dialog.h" | 47 #include "components/app_modal/javascript_app_modal_dialog.h" |
| 47 #include "components/app_modal/native_app_modal_dialog.h" | 48 #include "components/app_modal/native_app_modal_dialog.h" |
| 48 #include "components/prefs/pref_service.h" | 49 #include "components/prefs/pref_service.h" |
| 49 #include "content/public/browser/child_process_data.h" | 50 #include "content/public/browser/child_process_data.h" |
| 50 #include "content/public/browser/content_browser_client.h" | 51 #include "content/public/browser/content_browser_client.h" |
| 51 #include "content/public/browser/devtools_agent_host.h" | 52 #include "content/public/browser/devtools_agent_host.h" |
| 52 #include "content/public/browser/notification_registrar.h" | 53 #include "content/public/browser/notification_registrar.h" |
| 53 #include "content/public/browser/notification_service.h" | 54 #include "content/public/browser/notification_service.h" |
| 54 #include "content/public/browser/render_view_host.h" | 55 #include "content/public/browser/render_view_host.h" |
| 55 #include "content/public/browser/render_widget_host.h" | 56 #include "content/public/browser/render_widget_host.h" |
| 56 #include "content/public/browser/render_widget_host_view.h" | 57 #include "content/public/browser/render_widget_host_view.h" |
| 58 #include "content/public/browser/url_data_source.h" | |
| 57 #include "content/public/browser/web_contents.h" | 59 #include "content/public/browser/web_contents.h" |
| 60 #include "content/public/browser/web_ui_controller.h" | |
| 58 #include "content/public/browser/worker_service.h" | 61 #include "content/public/browser/worker_service.h" |
| 59 #include "content/public/browser/worker_service_observer.h" | 62 #include "content/public/browser/worker_service_observer.h" |
| 60 #include "content/public/common/content_switches.h" | 63 #include "content/public/common/content_switches.h" |
| 61 #include "content/public/test/browser_test_utils.h" | 64 #include "content/public/test/browser_test_utils.h" |
| 62 #include "content/public/test/test_navigation_observer.h" | 65 #include "content/public/test/test_navigation_observer.h" |
| 63 #include "extensions/browser/extension_registry.h" | 66 #include "extensions/browser/extension_registry.h" |
| 64 #include "extensions/browser/extension_system.h" | 67 #include "extensions/browser/extension_system.h" |
| 65 #include "extensions/browser/notification_types.h" | 68 #include "extensions/browser/notification_types.h" |
| 66 #include "extensions/common/switches.h" | 69 #include "extensions/common/switches.h" |
| 67 #include "extensions/common/value_builder.h" | 70 #include "extensions/common/value_builder.h" |
| (...skipping 1280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1348 void SetUpCommandLine(base::CommandLine* command_line) override { | 1351 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 1349 command_line->AppendSwitch(switches::kEnableNetworkInformation); | 1352 command_line->AppendSwitch(switches::kEnableNetworkInformation); |
| 1350 command_line->AppendSwitch( | 1353 command_line->AppendSwitch( |
| 1351 switches::kEnableExperimentalWebPlatformFeatures); | 1354 switches::kEnableExperimentalWebPlatformFeatures); |
| 1352 } | 1355 } |
| 1353 }; | 1356 }; |
| 1354 | 1357 |
| 1355 IN_PROC_BROWSER_TEST_F(DevToolsNetInfoTest, EmulateNetworkConditions) { | 1358 IN_PROC_BROWSER_TEST_F(DevToolsNetInfoTest, EmulateNetworkConditions) { |
| 1356 RunTest("testEmulateNetworkConditions", kEmulateNetworkConditionsPage); | 1359 RunTest("testEmulateNetworkConditions", kEmulateNetworkConditionsPage); |
| 1357 } | 1360 } |
| 1361 | |
| 1362 class StaticURLDataSource : public content::URLDataSource { | |
| 1363 public: | |
| 1364 StaticURLDataSource(const std::string& source, const std::string& content) | |
| 1365 : source_(source), content_(content) {} | |
| 1366 | |
| 1367 std::string GetSource() const override { return source_; } | |
| 1368 void StartDataRequest(const std::string& path, | |
| 1369 int render_process_id, | |
| 1370 int render_frame_id, | |
| 1371 const GotDataCallback& callback) override { | |
| 1372 std::string data(content_); | |
| 1373 callback.Run(base::RefCountedString::TakeString(&data)); | |
| 1374 } | |
| 1375 std::string GetMimeType(const std::string& path) const override { | |
| 1376 return "text/html"; | |
| 1377 } | |
| 1378 bool ShouldAddContentSecurityPolicy() const override { return false; } | |
|
kozy
2016/07/13 17:52:27
@tsepez, could I bypass CSP in test? There is "Do
Tom Sepez
2016/07/13 18:04:08
This should be fine for test code. Thanks.
| |
| 1379 | |
| 1380 private: | |
| 1381 std::string source_; | |
| 1382 std::string content_; | |
| 1383 DISALLOW_COPY_AND_ASSIGN(StaticURLDataSource); | |
| 1384 }; | |
| 1385 | |
| 1386 class MockWebUIProvider | |
| 1387 : public TestChromeWebUIControllerFactory::WebUIProvider { | |
| 1388 public: | |
| 1389 MockWebUIProvider(const std::string& source, const std::string& content) | |
| 1390 : source_(source), content_(content) {} | |
| 1391 | |
| 1392 content::WebUIController* NewWebUI(content::WebUI* web_ui, | |
| 1393 const GURL& url) override { | |
| 1394 content::URLDataSource::Add(Profile::FromWebUI(web_ui), | |
| 1395 new StaticURLDataSource(source_, content_)); | |
| 1396 return new content::WebUIController(web_ui); | |
| 1397 } | |
| 1398 | |
| 1399 private: | |
| 1400 std::string source_; | |
| 1401 std::string content_; | |
| 1402 DISALLOW_COPY_AND_ASSIGN(MockWebUIProvider); | |
| 1403 }; | |
| 1404 | |
| 1405 // This tests checks that window is correctly initialized when DevTools is | |
| 1406 // opened while navigation through history with forward and back actions. | |
| 1407 // (crbug.com/627407) | |
| 1408 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, | |
| 1409 TestWindowInitializedOnNavigateBack) { | |
| 1410 TestChromeWebUIControllerFactory test_factory; | |
| 1411 MockWebUIProvider mock_provider("dummyurl", | |
| 1412 "<script>\n" | |
| 1413 " window.abc = 239;\n" | |
| 1414 " console.log(abc);\n" | |
| 1415 "</script>"); | |
| 1416 test_factory.AddFactoryOverride(GURL("chrome://dummyurl").host(), | |
| 1417 &mock_provider); | |
| 1418 content::WebUIControllerFactory::RegisterFactory(&test_factory); | |
| 1419 | |
| 1420 ui_test_utils::NavigateToURL(browser(), GURL("chrome://dummyurl")); | |
| 1421 DevToolsWindow* window = | |
| 1422 DevToolsWindowTesting::OpenDevToolsWindowSync(GetInspectedTab(), true); | |
| 1423 chrome::DuplicateTab(browser()); | |
| 1424 chrome::SelectPreviousTab(browser()); | |
| 1425 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | |
| 1426 chrome::GoBack(browser(), CURRENT_TAB); | |
| 1427 RunTestFunction(window, "testWindowInitializedOnNavigateBack"); | |
| 1428 | |
| 1429 DevToolsWindowTesting::CloseDevToolsWindowSync(window); | |
| 1430 content::WebUIControllerFactory::UnregisterFactoryForTesting(&test_factory); | |
| 1431 } | |
| OLD | NEW |