| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/android/offline_pages/prerender_adapter.h" | 5 #include "chrome/browser/android/offline_pages/prerender_adapter.h" |
| 6 | 6 |
| 7 #include "base/sys_info.h" | 7 #include "base/sys_info.h" |
| 8 #include "chrome/browser/prerender/prerender_manager_factory.h" | 8 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 9 #include "chrome/test/base/testing_profile.h" | 9 #include "chrome/test/base/testing_profile.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 | 194 |
| 195 prerender_manager()->SetMode(PrerenderManager::PRERENDER_MODE_DISABLED); | 195 prerender_manager()->SetMode(PrerenderManager::PRERENDER_MODE_DISABLED); |
| 196 EXPECT_FALSE(adapter()->CanPrerender()); | 196 EXPECT_FALSE(adapter()->CanPrerender()); |
| 197 } | 197 } |
| 198 | 198 |
| 199 TEST_F(PrerenderAdapterTest, StartPrerenderFailsForUnsupportedScheme) { | 199 TEST_F(PrerenderAdapterTest, StartPrerenderFailsForUnsupportedScheme) { |
| 200 // Skip test on low end device until supported. | 200 // Skip test on low end device until supported. |
| 201 if (base::SysInfo::IsLowEndDevice()) | 201 if (base::SysInfo::IsLowEndDevice()) |
| 202 return; | 202 return; |
| 203 | 203 |
| 204 content::WebContents* session_contents = content::WebContents::Create( | 204 std::unique_ptr<content::WebContents> session_contents( |
| 205 content::WebContents::CreateParams(profile())); | 205 content::WebContents::Create( |
| 206 content::WebContents::CreateParams(profile()))); |
| 206 content::SessionStorageNamespace* sessionStorageNamespace = | 207 content::SessionStorageNamespace* sessionStorageNamespace = |
| 207 session_contents->GetController().GetDefaultSessionStorageNamespace(); | 208 session_contents->GetController().GetDefaultSessionStorageNamespace(); |
| 208 gfx::Size renderWindowSize = session_contents->GetContainerBounds().size(); | 209 gfx::Size renderWindowSize = session_contents->GetContainerBounds().size(); |
| 209 GURL url("file://file.test"); | 210 GURL url("file://file.test"); |
| 210 EXPECT_FALSE(adapter()->StartPrerender( | 211 EXPECT_FALSE(adapter()->StartPrerender( |
| 211 profile(), url, sessionStorageNamespace, renderWindowSize)); | 212 profile(), url, sessionStorageNamespace, renderWindowSize)); |
| 212 EXPECT_TRUE(prerender_contents_factory()->create_prerender_contents_called()); | 213 EXPECT_TRUE(prerender_contents_factory()->create_prerender_contents_called()); |
| 213 EXPECT_FALSE(adapter()->IsActive()); | 214 EXPECT_FALSE(adapter()->IsActive()); |
| 214 } | 215 } |
| 215 | 216 |
| 216 TEST_F(PrerenderAdapterTest, StartPrerenderSucceeds) { | 217 TEST_F(PrerenderAdapterTest, StartPrerenderSucceeds) { |
| 217 // Skip test on low end device until supported. | 218 // Skip test on low end device until supported. |
| 218 if (base::SysInfo::IsLowEndDevice()) | 219 if (base::SysInfo::IsLowEndDevice()) |
| 219 return; | 220 return; |
| 220 | 221 |
| 221 content::WebContents* session_contents = content::WebContents::Create( | 222 std::unique_ptr<content::WebContents> session_contents( |
| 222 content::WebContents::CreateParams(profile())); | 223 content::WebContents::Create( |
| 224 content::WebContents::CreateParams(profile()))); |
| 223 content::SessionStorageNamespace* sessionStorageNamespace = | 225 content::SessionStorageNamespace* sessionStorageNamespace = |
| 224 session_contents->GetController().GetDefaultSessionStorageNamespace(); | 226 session_contents->GetController().GetDefaultSessionStorageNamespace(); |
| 225 gfx::Size renderWindowSize = session_contents->GetContainerBounds().size(); | 227 gfx::Size renderWindowSize = session_contents->GetContainerBounds().size(); |
| 226 GURL url("https://url.test"); | 228 GURL url("https://url.test"); |
| 227 EXPECT_TRUE(adapter()->StartPrerender(profile(), url, sessionStorageNamespace, | 229 EXPECT_TRUE(adapter()->StartPrerender(profile(), url, sessionStorageNamespace, |
| 228 renderWindowSize)); | 230 renderWindowSize)); |
| 229 EXPECT_TRUE(prerender_contents_factory()->create_prerender_contents_called()); | 231 EXPECT_TRUE(prerender_contents_factory()->create_prerender_contents_called()); |
| 230 EXPECT_NE(nullptr, prerender_contents_factory()->last_prerender_contents()); | 232 EXPECT_NE(nullptr, prerender_contents_factory()->last_prerender_contents()); |
| 231 EXPECT_TRUE(adapter()->IsActive()); | 233 EXPECT_TRUE(adapter()->IsActive()); |
| 232 EXPECT_FALSE(observer_stop_loading_called()); | 234 EXPECT_FALSE(observer_stop_loading_called()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 246 EXPECT_EQ(FinalStatus::FINAL_STATUS_CANCELLED, adapter()->GetFinalStatus()); | 248 EXPECT_EQ(FinalStatus::FINAL_STATUS_CANCELLED, adapter()->GetFinalStatus()); |
| 247 | 249 |
| 248 // Exercise access methods even though no interesting values set beneath. | 250 // Exercise access methods even though no interesting values set beneath. |
| 249 EXPECT_EQ(nullptr, adapter()->GetWebContents()); | 251 EXPECT_EQ(nullptr, adapter()->GetWebContents()); |
| 250 | 252 |
| 251 adapter()->DestroyActive(); | 253 adapter()->DestroyActive(); |
| 252 EXPECT_FALSE(adapter()->IsActive()); | 254 EXPECT_FALSE(adapter()->IsActive()); |
| 253 } | 255 } |
| 254 | 256 |
| 255 } // namespace offline_pages | 257 } // namespace offline_pages |
| OLD | NEW |