| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/path_service.h" | 5 #include "base/path_service.h" |
| 6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/apps/app_browsertest_util.h" | 8 #include "chrome/browser/apps/app_browsertest_util.h" |
| 9 #include "chrome/browser/chrome_content_browser_client.h" | 9 #include "chrome/browser/chrome_content_browser_client.h" |
| 10 #include "chrome/browser/prerender/prerender_link_manager.h" | 10 #include "chrome/browser/prerender/prerender_link_manager.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 24 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
| 25 #include "content/public/browser/web_contents_delegate.h" | 25 #include "content/public/browser/web_contents_delegate.h" |
| 26 #include "content/public/common/content_switches.h" | 26 #include "content/public/common/content_switches.h" |
| 27 #include "content/public/test/browser_test_utils.h" | 27 #include "content/public/test/browser_test_utils.h" |
| 28 #include "content/public/test/fake_speech_recognition_manager.h" | 28 #include "content/public/test/fake_speech_recognition_manager.h" |
| 29 #include "content/public/test/test_renderer_host.h" | 29 #include "content/public/test/test_renderer_host.h" |
| 30 #include "extensions/browser/app_window/native_app_window.h" | 30 #include "extensions/browser/app_window/native_app_window.h" |
| 31 #include "extensions/browser/guest_view/guest_view_manager.h" | 31 #include "extensions/browser/guest_view/guest_view_manager.h" |
| 32 #include "extensions/browser/guest_view/guest_view_manager_factory.h" | 32 #include "extensions/browser/guest_view/guest_view_manager_factory.h" |
| 33 #include "extensions/browser/guest_view/web_view/web_view_test_common.h" |
| 33 #include "extensions/common/extension.h" | 34 #include "extensions/common/extension.h" |
| 34 #include "extensions/common/extensions_client.h" | 35 #include "extensions/common/extensions_client.h" |
| 35 #include "extensions/test/extension_test_message_listener.h" | 36 #include "extensions/test/extension_test_message_listener.h" |
| 36 #include "media/base/media_switches.h" | 37 #include "media/base/media_switches.h" |
| 37 #include "net/test/embedded_test_server/embedded_test_server.h" | 38 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 38 #include "net/test/embedded_test_server/http_request.h" | 39 #include "net/test/embedded_test_server/http_request.h" |
| 39 #include "net/test/embedded_test_server/http_response.h" | 40 #include "net/test/embedded_test_server/http_response.h" |
| 40 #include "ui/gfx/switches.h" | 41 #include "ui/gfx/switches.h" |
| 41 #include "ui/gl/gl_switches.h" | 42 #include "ui/gl/gl_switches.h" |
| 42 | 43 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 }; | 89 }; |
| 89 | 90 |
| 90 class TestInterstitialPageDelegate : public content::InterstitialPageDelegate { | 91 class TestInterstitialPageDelegate : public content::InterstitialPageDelegate { |
| 91 public: | 92 public: |
| 92 TestInterstitialPageDelegate() { | 93 TestInterstitialPageDelegate() { |
| 93 } | 94 } |
| 94 virtual ~TestInterstitialPageDelegate() {} | 95 virtual ~TestInterstitialPageDelegate() {} |
| 95 virtual std::string GetHTMLContents() OVERRIDE { return std::string(); } | 96 virtual std::string GetHTMLContents() OVERRIDE { return std::string(); } |
| 96 }; | 97 }; |
| 97 | 98 |
| 98 class TestGuestViewManager : public extensions::GuestViewManager { | |
| 99 public: | |
| 100 explicit TestGuestViewManager(content::BrowserContext* context) : | |
| 101 GuestViewManager(context), | |
| 102 seen_guest_removed_(false), | |
| 103 web_contents_(NULL) {} | |
| 104 | |
| 105 content::WebContents* WaitForGuestCreated() { | |
| 106 if (web_contents_) | |
| 107 return web_contents_; | |
| 108 | |
| 109 created_message_loop_runner_ = new content::MessageLoopRunner; | |
| 110 created_message_loop_runner_->Run(); | |
| 111 return web_contents_; | |
| 112 } | |
| 113 | |
| 114 void WaitForGuestDeleted() { | |
| 115 if (seen_guest_removed_) | |
| 116 return; | |
| 117 | |
| 118 deleted_message_loop_runner_ = new content::MessageLoopRunner; | |
| 119 deleted_message_loop_runner_->Run(); | |
| 120 } | |
| 121 | |
| 122 private: | |
| 123 // GuestViewManager override: | |
| 124 virtual void AddGuest(int guest_instance_id, | |
| 125 content::WebContents* guest_web_contents) OVERRIDE{ | |
| 126 extensions::GuestViewManager::AddGuest( | |
| 127 guest_instance_id, guest_web_contents); | |
| 128 web_contents_ = guest_web_contents; | |
| 129 seen_guest_removed_ = false; | |
| 130 | |
| 131 if (created_message_loop_runner_.get()) | |
| 132 created_message_loop_runner_->Quit(); | |
| 133 } | |
| 134 | |
| 135 virtual void RemoveGuest(int guest_instance_id) OVERRIDE { | |
| 136 extensions::GuestViewManager::RemoveGuest(guest_instance_id); | |
| 137 web_contents_ = NULL; | |
| 138 seen_guest_removed_ = true; | |
| 139 | |
| 140 if (deleted_message_loop_runner_.get()) | |
| 141 deleted_message_loop_runner_->Quit(); | |
| 142 } | |
| 143 | |
| 144 bool seen_guest_removed_; | |
| 145 content::WebContents* web_contents_; | |
| 146 scoped_refptr<content::MessageLoopRunner> created_message_loop_runner_; | |
| 147 scoped_refptr<content::MessageLoopRunner> deleted_message_loop_runner_; | |
| 148 }; | |
| 149 | |
| 150 // Test factory for creating test instances of GuestViewManager. | |
| 151 class TestGuestViewManagerFactory : | |
| 152 public extensions::GuestViewManagerFactory { | |
| 153 public: | |
| 154 TestGuestViewManagerFactory() : | |
| 155 test_guest_view_manager_(NULL) {} | |
| 156 | |
| 157 virtual ~TestGuestViewManagerFactory() {} | |
| 158 | |
| 159 virtual extensions::GuestViewManager* CreateGuestViewManager( | |
| 160 content::BrowserContext* context) OVERRIDE { | |
| 161 return GetManager(context); | |
| 162 } | |
| 163 | |
| 164 TestGuestViewManager* GetManager(content::BrowserContext* context) { | |
| 165 if (!test_guest_view_manager_) { | |
| 166 test_guest_view_manager_ = new TestGuestViewManager(context); | |
| 167 } | |
| 168 return test_guest_view_manager_; | |
| 169 } | |
| 170 | |
| 171 private: | |
| 172 TestGuestViewManager* test_guest_view_manager_; | |
| 173 | |
| 174 DISALLOW_COPY_AND_ASSIGN(TestGuestViewManagerFactory); | |
| 175 }; | |
| 176 | |
| 177 class WebContentsHiddenObserver : public content::WebContentsObserver { | 99 class WebContentsHiddenObserver : public content::WebContentsObserver { |
| 178 public: | 100 public: |
| 179 WebContentsHiddenObserver(content::WebContents* web_contents, | 101 WebContentsHiddenObserver(content::WebContents* web_contents, |
| 180 const base::Closure& hidden_callback) | 102 const base::Closure& hidden_callback) |
| 181 : WebContentsObserver(web_contents), | 103 : WebContentsObserver(web_contents), |
| 182 hidden_callback_(hidden_callback), | 104 hidden_callback_(hidden_callback), |
| 183 hidden_observed_(false) { | 105 hidden_observed_(false) { |
| 184 } | 106 } |
| 185 | 107 |
| 186 // WebContentsObserver. | 108 // WebContentsObserver. |
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 return guest_web_contents_; | 659 return guest_web_contents_; |
| 738 } | 660 } |
| 739 | 661 |
| 740 content::WebContents* GetEmbedderWebContents() { | 662 content::WebContents* GetEmbedderWebContents() { |
| 741 if (!embedder_web_contents_) { | 663 if (!embedder_web_contents_) { |
| 742 embedder_web_contents_ = GetFirstAppWindowWebContents(); | 664 embedder_web_contents_ = GetFirstAppWindowWebContents(); |
| 743 } | 665 } |
| 744 return embedder_web_contents_; | 666 return embedder_web_contents_; |
| 745 } | 667 } |
| 746 | 668 |
| 747 TestGuestViewManager* GetGuestViewManager() { | 669 extensions::TestGuestViewManager* GetGuestViewManager() { |
| 748 return factory_.GetManager(browser()->profile()); | 670 return static_cast<extensions::TestGuestViewManager*>( |
| 671 extensions::TestGuestViewManager::FromBrowserContext( |
| 672 browser()->profile())); |
| 749 } | 673 } |
| 750 | 674 |
| 751 WebViewTest() : guest_web_contents_(NULL), | 675 WebViewTest() : guest_web_contents_(NULL), |
| 752 embedder_web_contents_(NULL) { | 676 embedder_web_contents_(NULL) { |
| 753 extensions::GuestViewManager::set_factory_for_testing(&factory_); | 677 extensions::GuestViewManager::set_factory_for_testing(&factory_); |
| 754 } | 678 } |
| 755 | 679 |
| 756 private: | 680 private: |
| 757 bool UsesFakeSpeech() { | 681 bool UsesFakeSpeech() { |
| 758 const testing::TestInfo* const test_info = | 682 const testing::TestInfo* const test_info = |
| 759 testing::UnitTest::GetInstance()->current_test_info(); | 683 testing::UnitTest::GetInstance()->current_test_info(); |
| 760 | 684 |
| 761 // SpeechRecognition test specific SetUp. | 685 // SpeechRecognition test specific SetUp. |
| 762 return !strcmp(test_info->name(), | 686 return !strcmp(test_info->name(), |
| 763 "SpeechRecognitionAPI_HasPermissionAllow"); | 687 "SpeechRecognitionAPI_HasPermissionAllow"); |
| 764 } | 688 } |
| 765 | 689 |
| 766 scoped_ptr<content::FakeSpeechRecognitionManager> | 690 scoped_ptr<content::FakeSpeechRecognitionManager> |
| 767 fake_speech_recognition_manager_; | 691 fake_speech_recognition_manager_; |
| 768 | 692 |
| 769 TestGuestViewManagerFactory factory_; | 693 extensions::TestGuestViewManagerFactory factory_; |
| 770 // Note that these are only set if you launch app using LoadAppWithGuest(). | 694 // Note that these are only set if you launch app using LoadAppWithGuest(). |
| 771 content::WebContents* guest_web_contents_; | 695 content::WebContents* guest_web_contents_; |
| 772 content::WebContents* embedder_web_contents_; | 696 content::WebContents* embedder_web_contents_; |
| 773 }; | 697 }; |
| 774 | 698 |
| 775 class WebViewDPITest : public WebViewTest { | 699 class WebViewDPITest : public WebViewTest { |
| 776 protected: | 700 protected: |
| 777 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 701 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 778 WebViewTest::SetUpCommandLine(command_line); | 702 WebViewTest::SetUpCommandLine(command_line); |
| 779 command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor, | 703 command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor, |
| (...skipping 1568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2348 // http://crbug.com/403325 | 2272 // http://crbug.com/403325 |
| 2349 #define MAYBE_WebViewInBackgroundPage \ | 2273 #define MAYBE_WebViewInBackgroundPage \ |
| 2350 DISABLED_WebViewInBackgroundPage | 2274 DISABLED_WebViewInBackgroundPage |
| 2351 #else | 2275 #else |
| 2352 #define MAYBE_WebViewInBackgroundPage WebViewInBackgroundPage | 2276 #define MAYBE_WebViewInBackgroundPage WebViewInBackgroundPage |
| 2353 #endif | 2277 #endif |
| 2354 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_WebViewInBackgroundPage) { | 2278 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_WebViewInBackgroundPage) { |
| 2355 ASSERT_TRUE(RunExtensionTest("platform_apps/web_view/background")) | 2279 ASSERT_TRUE(RunExtensionTest("platform_apps/web_view/background")) |
| 2356 << message_; | 2280 << message_; |
| 2357 } | 2281 } |
| OLD | NEW |