| 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 "ash/test/ash_test_environment_content.h" | 5 #include "ash/test/ash_test_environment_content.h" |
| 6 | 6 |
| 7 #include "ash/test/ash_test_views_delegate.h" | 7 #include "ash/test/ash_test_views_delegate.h" |
| 8 #include "ash/test/content/test_shell_content_state.h" | 8 #include "ash/test/content/test_shell_content_state.h" |
| 9 #include "base/files/file_path.h" |
| 9 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/path_service.h" |
| 10 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/test/test_browser_thread_bundle.h" | 13 #include "content/public/test/test_browser_thread_bundle.h" |
| 12 #include "content/public/test/web_contents_tester.h" | 14 #include "content/public/test/web_contents_tester.h" |
| 15 #include "ui/base/resource/resource_bundle.h" |
| 13 | 16 |
| 14 namespace ash { | 17 namespace ash { |
| 15 namespace test { | 18 namespace test { |
| 16 namespace { | 19 namespace { |
| 17 | 20 |
| 18 class AshTestViewsDelegateContent : public AshTestViewsDelegate { | 21 class AshTestViewsDelegateContent : public AshTestViewsDelegate { |
| 19 public: | 22 public: |
| 20 AshTestViewsDelegateContent() {} | 23 AshTestViewsDelegateContent() {} |
| 21 ~AshTestViewsDelegateContent() override {} | 24 ~AshTestViewsDelegateContent() override {} |
| 22 | 25 |
| 23 // AshTestViewsDelegate: | 26 // AshTestViewsDelegate: |
| 24 content::WebContents* CreateWebContents( | 27 content::WebContents* CreateWebContents( |
| 25 content::BrowserContext* browser_context, | 28 content::BrowserContext* browser_context, |
| 26 content::SiteInstance* site_instance) override { | 29 content::SiteInstance* site_instance) override { |
| 27 return content::WebContentsTester::CreateTestWebContents(browser_context, | 30 return content::WebContentsTester::CreateTestWebContents(browser_context, |
| 28 site_instance); | 31 site_instance); |
| 29 } | 32 } |
| 30 | 33 |
| 31 private: | 34 private: |
| 32 DISALLOW_COPY_AND_ASSIGN(AshTestViewsDelegateContent); | 35 DISALLOW_COPY_AND_ASSIGN(AshTestViewsDelegateContent); |
| 33 }; | 36 }; |
| 34 | 37 |
| 35 } // namespace | 38 } // namespace |
| 36 | 39 |
| 37 // static | 40 // static |
| 38 std::unique_ptr<AshTestEnvironment> AshTestEnvironment::Create() { | 41 std::unique_ptr<AshTestEnvironment> AshTestEnvironment::Create() { |
| 39 return base::MakeUnique<AshTestEnvironmentContent>(); | 42 return base::MakeUnique<AshTestEnvironmentContent>(); |
| 40 } | 43 } |
| 41 | 44 |
| 45 // static |
| 46 void AshTestEnvironment::AddDataPacks() { |
| 47 base::FilePath path; |
| 48 PathService::Get(base::DIR_MODULE, &path); |
| 49 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 50 if (ui::ResourceBundle::IsScaleFactorSupported(ui::SCALE_FACTOR_100P)) { |
| 51 base::FilePath ash_test_resources_100 = path.Append( |
| 52 FILE_PATH_LITERAL("ash_test_resources_content_100_percent.pak")); |
| 53 rb.AddDataPackFromPath(ash_test_resources_100, ui::SCALE_FACTOR_100P); |
| 54 } |
| 55 } |
| 56 |
| 42 AshTestEnvironmentContent::AshTestEnvironmentContent() | 57 AshTestEnvironmentContent::AshTestEnvironmentContent() |
| 43 : thread_bundle_(base::MakeUnique<content::TestBrowserThreadBundle>()) {} | 58 : thread_bundle_(base::MakeUnique<content::TestBrowserThreadBundle>()) {} |
| 44 | 59 |
| 45 AshTestEnvironmentContent::~AshTestEnvironmentContent() {} | 60 AshTestEnvironmentContent::~AshTestEnvironmentContent() {} |
| 46 | 61 |
| 47 void AshTestEnvironmentContent::SetUp() { | 62 void AshTestEnvironmentContent::SetUp() { |
| 48 ShellContentState* content_state = content_state_; | 63 ShellContentState* content_state = content_state_; |
| 49 if (!content_state) { | 64 if (!content_state) { |
| 50 test_shell_content_state_ = new TestShellContentState; | 65 test_shell_content_state_ = new TestShellContentState; |
| 51 content_state = test_shell_content_state_; | 66 content_state = test_shell_content_state_; |
| 52 } | 67 } |
| 53 ShellContentState::SetInstance(content_state); | 68 ShellContentState::SetInstance(content_state); |
| 54 } | 69 } |
| 55 | 70 |
| 56 void AshTestEnvironmentContent::TearDown() { | 71 void AshTestEnvironmentContent::TearDown() { |
| 57 ShellContentState::DestroyInstance(); | 72 ShellContentState::DestroyInstance(); |
| 58 } | 73 } |
| 59 | 74 |
| 60 base::SequencedWorkerPool* AshTestEnvironmentContent::GetBlockingPool() { | 75 base::SequencedWorkerPool* AshTestEnvironmentContent::GetBlockingPool() { |
| 61 return content::BrowserThread::GetBlockingPool(); | 76 return content::BrowserThread::GetBlockingPool(); |
| 62 } | 77 } |
| 63 | 78 |
| 64 std::unique_ptr<views::ViewsDelegate> | 79 std::unique_ptr<views::ViewsDelegate> |
| 65 AshTestEnvironmentContent::CreateViewsDelegate() { | 80 AshTestEnvironmentContent::CreateViewsDelegate() { |
| 66 return base::MakeUnique<AshTestViewsDelegateContent>(); | 81 return base::MakeUnique<AshTestViewsDelegateContent>(); |
| 67 } | 82 } |
| 68 | 83 |
| 69 } // namespace test | 84 } // namespace test |
| 70 } // namespace ash | 85 } // namespace ash |
| OLD | NEW |