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