OLD | NEW |
(Empty) | |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/chrome/browser/ui/chrome_web_view_factory.h" |
| 6 |
| 7 #include "base/mac/scoped_nsobject.h" |
| 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" |
| 11 #include "ios/chrome/browser/browser_state/test_chrome_browser_state_isolated_co
ntext.h" |
| 12 #import "ios/chrome/browser/web/chrome_web_client.h" |
| 13 #include "ios/web/net/request_group_util.h" |
| 14 #include "ios/web/net/request_tracker_impl.h" |
| 15 #include "ios/web/public/test/scoped_testing_web_client.h" |
| 16 #include "ios/web/public/test/test_web_thread.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "testing/gtest_mac.h" |
| 19 #include "testing/platform_test.h" |
| 20 #import "third_party/ocmock/OCMock/OCMock.h" |
| 21 #import "third_party/ocmock/gtest_support.h" |
| 22 |
| 23 using web::RequestTrackerImpl; |
| 24 |
| 25 namespace { |
| 26 |
| 27 class ChromeWebViewFactoryTest : public PlatformTest { |
| 28 public: |
| 29 ChromeWebViewFactoryTest() |
| 30 : ui_thread_(web::WebThread::UI, &message_loop_), |
| 31 io_thread_(web::WebThread::IO, &message_loop_), |
| 32 web_client_(base::MakeUnique<ChromeWebClient>()) {} |
| 33 |
| 34 protected: |
| 35 base::MessageLoop message_loop_; |
| 36 web::TestWebThread ui_thread_; |
| 37 web::TestWebThread io_thread_; |
| 38 web::ScopedTestingWebClient web_client_; |
| 39 TestChromeBrowserStateWithIsolatedContext chrome_browser_state_; |
| 40 |
| 41 private: |
| 42 DISALLOW_COPY_AND_ASSIGN(ChromeWebViewFactoryTest); |
| 43 }; |
| 44 |
| 45 TEST_F(ChromeWebViewFactoryTest, TestTrackerForExternal) { |
| 46 [ChromeWebViewFactory setBrowserStateToUseForExternal:&chrome_browser_state_]; |
| 47 base::scoped_nsobject<UIWebView> webView([ChromeWebViewFactory |
| 48 newExternalWebView:chrome_browser_state_.SharingService()]); |
| 49 // Check that the tracker is registered |
| 50 RequestTrackerImpl* tracker = RequestTrackerImpl::GetTrackerForRequestGroupID( |
| 51 ChromeWebView::kExternalRequestGroupID); |
| 52 EXPECT_TRUE(tracker) << "Tracker not registered."; |
| 53 // External should use the request context for the sharing service, and not |
| 54 // the main one. |
| 55 net::URLRequestContextGetter* expected_getter = [ChromeWebViewFactory |
| 56 requestContextForExternalService:chrome_browser_state_.SharingService()]; |
| 57 EXPECT_EQ(expected_getter->GetURLRequestContext(), |
| 58 tracker->GetRequestContext()); |
| 59 EXPECT_FALSE(chrome_browser_state_.MainContextCalled()); |
| 60 // Unregister the tracker. |
| 61 [ChromeWebViewFactory externalSessionFinished]; |
| 62 base::RunLoop().RunUntilIdle(); |
| 63 EXPECT_FALSE(RequestTrackerImpl::GetTrackerForRequestGroupID( |
| 64 ChromeWebView::kExternalRequestGroupID)); |
| 65 [ChromeWebViewFactory setBrowserStateToUseForExternal:nullptr]; |
| 66 } |
| 67 |
| 68 } // namespace |
OLD | NEW |