| 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 <deque> | 5 #include <deque> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 #include "content/public/browser/navigation_entry.h" | 77 #include "content/public/browser/navigation_entry.h" |
| 78 #include "content/public/browser/notification_service.h" | 78 #include "content/public/browser/notification_service.h" |
| 79 #include "content/public/browser/render_frame_host.h" | 79 #include "content/public/browser/render_frame_host.h" |
| 80 #include "content/public/browser/render_process_host.h" | 80 #include "content/public/browser/render_process_host.h" |
| 81 #include "content/public/browser/render_view_host.h" | 81 #include "content/public/browser/render_view_host.h" |
| 82 #include "content/public/browser/site_instance.h" | 82 #include "content/public/browser/site_instance.h" |
| 83 #include "content/public/browser/web_contents.h" | 83 #include "content/public/browser/web_contents.h" |
| 84 #include "content/public/browser/web_contents_observer.h" | 84 #include "content/public/browser/web_contents_observer.h" |
| 85 #include "content/public/common/url_constants.h" | 85 #include "content/public/common/url_constants.h" |
| 86 #include "content/public/test/browser_test_utils.h" | 86 #include "content/public/test/browser_test_utils.h" |
| 87 #include "content/public/test/ppapi_test_utils.h" |
| 87 #include "content/public/test/test_navigation_observer.h" | 88 #include "content/public/test/test_navigation_observer.h" |
| 88 #include "content/public/test/test_utils.h" | 89 #include "content/public/test/test_utils.h" |
| 89 #include "extensions/common/constants.h" | 90 #include "extensions/common/constants.h" |
| 90 #include "extensions/common/extension_urls.h" | 91 #include "extensions/common/extension_urls.h" |
| 91 #include "extensions/common/manifest_handlers/mime_types_handler.h" | 92 #include "extensions/common/manifest_handlers/mime_types_handler.h" |
| 92 #include "extensions/common/switches.h" | 93 #include "extensions/common/switches.h" |
| 93 #include "extensions/test/result_catcher.h" | 94 #include "extensions/test/result_catcher.h" |
| 94 #include "net/base/escape.h" | 95 #include "net/base/escape.h" |
| 95 #include "net/cert/x509_certificate.h" | 96 #include "net/cert/x509_certificate.h" |
| 96 #include "net/dns/mock_host_resolver.h" | 97 #include "net/dns/mock_host_resolver.h" |
| (...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1065 }; | 1066 }; |
| 1066 | 1067 |
| 1067 base::FilePath GetTestPath(const std::string& file_name) { | 1068 base::FilePath GetTestPath(const std::string& file_name) { |
| 1068 return ui_test_utils::GetTestFilePath( | 1069 return ui_test_utils::GetTestFilePath( |
| 1069 base::FilePath(FILE_PATH_LITERAL("prerender")), | 1070 base::FilePath(FILE_PATH_LITERAL("prerender")), |
| 1070 base::FilePath().AppendASCII(file_name)); | 1071 base::FilePath().AppendASCII(file_name)); |
| 1071 } | 1072 } |
| 1072 | 1073 |
| 1073 } // namespace | 1074 } // namespace |
| 1074 | 1075 |
| 1075 // Many of these tests are flaky. See http://crbug.com/249179 | |
| 1076 class PrerenderBrowserTest : virtual public InProcessBrowserTest { | 1076 class PrerenderBrowserTest : virtual public InProcessBrowserTest { |
| 1077 public: | 1077 public: |
| 1078 PrerenderBrowserTest() | 1078 PrerenderBrowserTest() |
| 1079 : autostart_test_server_(true), | 1079 : autostart_test_server_(true), |
| 1080 prerender_contents_factory_(NULL), | 1080 prerender_contents_factory_(NULL), |
| 1081 #if defined(FULL_SAFE_BROWSING) | 1081 #if defined(FULL_SAFE_BROWSING) |
| 1082 safe_browsing_factory_(new TestSafeBrowsingServiceFactory()), | 1082 safe_browsing_factory_(new TestSafeBrowsingServiceFactory()), |
| 1083 #endif | 1083 #endif |
| 1084 call_javascript_(true), | 1084 call_javascript_(true), |
| 1085 check_load_events_(true), | 1085 check_load_events_(true), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1103 | 1103 |
| 1104 void TearDownInProcessBrowserTestFixture() override { | 1104 void TearDownInProcessBrowserTestFixture() override { |
| 1105 #if defined(FULL_SAFE_BROWSING) | 1105 #if defined(FULL_SAFE_BROWSING) |
| 1106 SafeBrowsingService::RegisterFactory(NULL); | 1106 SafeBrowsingService::RegisterFactory(NULL); |
| 1107 #endif | 1107 #endif |
| 1108 } | 1108 } |
| 1109 | 1109 |
| 1110 void SetUpCommandLine(base::CommandLine* command_line) override { | 1110 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 1111 command_line->AppendSwitchASCII(switches::kPrerenderMode, | 1111 command_line->AppendSwitchASCII(switches::kPrerenderMode, |
| 1112 switches::kPrerenderModeSwitchValueEnabled); | 1112 switches::kPrerenderModeSwitchValueEnabled); |
| 1113 #if defined(OS_MACOSX) | 1113 ASSERT_TRUE(ppapi::RegisterTestPlugin(command_line)); |
| 1114 // The plugins directory isn't read by default on the Mac, so it needs to be | |
| 1115 // explicitly registered. | |
| 1116 base::FilePath app_dir; | |
| 1117 PathService::Get(chrome::DIR_APP, &app_dir); | |
| 1118 command_line->AppendSwitchPath( | |
| 1119 switches::kExtraPluginDir, | |
| 1120 app_dir.Append(FILE_PATH_LITERAL("plugins"))); | |
| 1121 #endif | |
| 1122 command_line->AppendSwitch(switches::kAlwaysAuthorizePlugins); | |
| 1123 command_line->AppendSwitch(switches::kEnableNpapi); | |
| 1124 } | 1114 } |
| 1125 | 1115 |
| 1126 void SetPreference(NetworkPredictionOptions value) { | 1116 void SetPreference(NetworkPredictionOptions value) { |
| 1127 browser()->profile()->GetPrefs()->SetInteger( | 1117 browser()->profile()->GetPrefs()->SetInteger( |
| 1128 prefs::kNetworkPredictionOptions, value); | 1118 prefs::kNetworkPredictionOptions, value); |
| 1129 } | 1119 } |
| 1130 | 1120 |
| 1131 // Verifies whether ShouldDisableLocalPredictorDueToPreferencesAndNetwork | 1121 // Verifies whether ShouldDisableLocalPredictorDueToPreferencesAndNetwork |
| 1132 // produces the desired output. | 1122 // produces the desired output. |
| 1133 void TestShouldDisableLocalPredictorPreferenceNetworkMatrix( | 1123 void TestShouldDisableLocalPredictorPreferenceNetworkMatrix( |
| (...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2038 // Checks that the prerendering of a page is canceled correctly when a | 2028 // Checks that the prerendering of a page is canceled correctly when a |
| 2039 // Javascript alert is called. | 2029 // Javascript alert is called. |
| 2040 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderAlertAfterOnload) { | 2030 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderAlertAfterOnload) { |
| 2041 PrerenderTestURL("files/prerender/prerender_alert_after_onload.html", | 2031 PrerenderTestURL("files/prerender/prerender_alert_after_onload.html", |
| 2042 FINAL_STATUS_JAVASCRIPT_ALERT, | 2032 FINAL_STATUS_JAVASCRIPT_ALERT, |
| 2043 1); | 2033 1); |
| 2044 } | 2034 } |
| 2045 | 2035 |
| 2046 // Checks that plugins are not loaded while a page is being preloaded, but | 2036 // Checks that plugins are not loaded while a page is being preloaded, but |
| 2047 // are loaded when the page is displayed. | 2037 // are loaded when the page is displayed. |
| 2048 #if defined(USE_AURA) && !defined(OS_WIN) | 2038 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderDelayLoadPlugin) { |
| 2049 // http://crbug.com/103496 | 2039 PrerenderTestURL("files/prerender/plugin_delay_load.html", FINAL_STATUS_USED, |
| 2050 #define MAYBE_PrerenderDelayLoadPlugin DISABLED_PrerenderDelayLoadPlugin | |
| 2051 #define MAYBE_PrerenderPluginPowerSaver DISABLED_PrerenderPluginPowerSaver | |
| 2052 #elif defined(OS_MACOSX) | |
| 2053 // http://crbug.com/100514 | |
| 2054 #define MAYBE_PrerenderDelayLoadPlugin DISABLED_PrerenderDelayLoadPlugin | |
| 2055 #define MAYBE_PrerenderPluginPowerSaver DISABLED_PrerenderPluginPowerSaver | |
| 2056 #elif defined(OS_WIN) && defined(ARCH_CPU_X86_64) | |
| 2057 // TODO(jschuh): Failing plugin tests. crbug.com/244653 | |
| 2058 #define MAYBE_PrerenderDelayLoadPlugin DISABLED_PrerenderDelayLoadPlugin | |
| 2059 #define MAYBE_PrerenderPluginPowerSaver DISABLED_PrerenderPluginPowerSaver | |
| 2060 #elif defined(OS_LINUX) | |
| 2061 // http://crbug.com/306715 | |
| 2062 #define MAYBE_PrerenderDelayLoadPlugin DISABLED_PrerenderDelayLoadPlugin | |
| 2063 #define MAYBE_PrerenderPluginPowerSaver DISABLED_PrerenderPluginPowerSaver | |
| 2064 #else | |
| 2065 #define MAYBE_PrerenderDelayLoadPlugin PrerenderDelayLoadPlugin | |
| 2066 #define MAYBE_PrerenderPluginPowerSaver PrerenderPluginPowerSaver | |
| 2067 #endif | |
| 2068 // http://crbug.com/306715 | |
| 2069 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, MAYBE_PrerenderDelayLoadPlugin) { | |
| 2070 PrerenderTestURL("files/prerender/plugin_delay_load.html", | |
| 2071 FINAL_STATUS_USED, | |
| 2072 1); | 2040 1); |
| 2073 NavigateToDestURL(); | 2041 NavigateToDestURL(); |
| 2074 } | 2042 } |
| 2075 | 2043 |
| 2076 // For enabled Plugin Power Saver, checks that plugins are not loaded while | 2044 // For Content Setting DETECT, checks that plugins are not loaded while |
| 2077 // a page is being preloaded, but are loaded when the page is displayed. | 2045 // a page is being preloaded, but are loaded when the page is displayed. |
| 2078 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, MAYBE_PrerenderPluginPowerSaver) { | 2046 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderContentSettingDetect) { |
| 2079 // Enable click-to-play. | |
| 2080 HostContentSettingsMap* content_settings_map = | 2047 HostContentSettingsMap* content_settings_map = |
| 2081 current_browser()->profile()->GetHostContentSettingsMap(); | 2048 current_browser()->profile()->GetHostContentSettingsMap(); |
| 2082 content_settings_map->SetDefaultContentSetting( | 2049 content_settings_map->SetDefaultContentSetting( |
| 2083 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); | 2050 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_DETECT_IMPORTANT_CONTENT); |
| 2084 | 2051 |
| 2085 PrerenderTestURL("files/prerender/prerender_plugin_power_saver.html", | 2052 PrerenderTestURL("files/prerender/plugin_delay_load.html", FINAL_STATUS_USED, |
| 2086 FINAL_STATUS_USED, 1); | 2053 1); |
| 2087 NavigateToDestURL(); | 2054 NavigateToDestURL(); |
| 2088 } | 2055 } |
| 2089 | 2056 |
| 2057 // For Content Setting BLOCK, checks that plugins are never loaded. |
| 2058 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderContentSettingBlock) { |
| 2059 HostContentSettingsMap* content_settings_map = |
| 2060 current_browser()->profile()->GetHostContentSettingsMap(); |
| 2061 content_settings_map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
| 2062 CONTENT_SETTING_BLOCK); |
| 2063 |
| 2064 PrerenderTestURL("files/prerender/plugin_never_load.html", FINAL_STATUS_USED, |
| 2065 1); |
| 2066 NavigateToDestURL(); |
| 2067 } |
| 2068 |
| 2090 // Checks that we don't load a NaCl plugin when NaCl is disabled. | 2069 // Checks that we don't load a NaCl plugin when NaCl is disabled. |
| 2091 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNaClPluginDisabled) { | 2070 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNaClPluginDisabled) { |
| 2092 PrerenderTestURL("files/prerender/prerender_plugin_nacl_disabled.html", | 2071 PrerenderTestURL("files/prerender/prerender_plugin_nacl_disabled.html", |
| 2093 FINAL_STATUS_USED, | 2072 FINAL_STATUS_USED, |
| 2094 1); | 2073 1); |
| 2095 NavigateToDestURL(); | 2074 NavigateToDestURL(); |
| 2096 | 2075 |
| 2097 | 2076 |
| 2098 // Run this check again. When we try to load aa ppapi plugin, the | 2077 // Run this check again. When we try to load aa ppapi plugin, the |
| 2099 // "loadstart" event is asynchronously posted to a message loop. | 2078 // "loadstart" event is asynchronously posted to a message loop. |
| (...skipping 2052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4152 TestShouldDisableLocalPredictorPreferenceNetworkMatrix( | 4131 TestShouldDisableLocalPredictorPreferenceNetworkMatrix( |
| 4153 false /*preference_wifi_network_wifi*/, | 4132 false /*preference_wifi_network_wifi*/, |
| 4154 false /*preference_wifi_network_4g*/, | 4133 false /*preference_wifi_network_4g*/, |
| 4155 false /*preference_always_network_wifi*/, | 4134 false /*preference_always_network_wifi*/, |
| 4156 false /*preference_always_network_4g*/, | 4135 false /*preference_always_network_4g*/, |
| 4157 false /*preference_never_network_wifi*/, | 4136 false /*preference_never_network_wifi*/, |
| 4158 false /*preference_never_network_4g*/); | 4137 false /*preference_never_network_4g*/); |
| 4159 } | 4138 } |
| 4160 | 4139 |
| 4161 } // namespace prerender | 4140 } // namespace prerender |
| OLD | NEW |