| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/offline_pages/content/background_loader/background_loader_c
ontents.h" |
| 6 |
| 7 #include "base/synchronization/waitable_event.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "url/gurl.h" |
| 10 |
| 11 namespace background_loader { |
| 12 |
| 13 class BackgroundLoaderContentsTest : public testing::Test { |
| 14 public: |
| 15 BackgroundLoaderContentsTest(); |
| 16 ~BackgroundLoaderContentsTest() override; |
| 17 |
| 18 void SetUp() override; |
| 19 void TearDown() override; |
| 20 |
| 21 BackgroundLoaderContents* contents() { return contents_.get(); } |
| 22 |
| 23 void DownloadCallback(bool download); |
| 24 |
| 25 bool download() { return download_; } |
| 26 |
| 27 void MediaAccessCallback(const content::MediaStreamDevices& devices, |
| 28 content::MediaStreamRequestResult result, |
| 29 std::unique_ptr<content::MediaStreamUI> ui); |
| 30 content::MediaStreamDevices devices() { return devices_; } |
| 31 content::MediaStreamRequestResult request_result() { return request_result_; } |
| 32 content::MediaStreamUI* media_stream_ui() { return media_stream_ui_.get(); } |
| 33 |
| 34 void WaitForSignal() { waiter_.Wait(); } |
| 35 |
| 36 private: |
| 37 std::unique_ptr<BackgroundLoaderContents> contents_; |
| 38 bool download_; |
| 39 content::MediaStreamDevices devices_; |
| 40 content::MediaStreamRequestResult request_result_; |
| 41 std::unique_ptr<content::MediaStreamUI> media_stream_ui_; |
| 42 base::WaitableEvent waiter_; |
| 43 }; |
| 44 |
| 45 BackgroundLoaderContentsTest::BackgroundLoaderContentsTest() |
| 46 : download_(false), |
| 47 waiter_(base::WaitableEvent::ResetPolicy::MANUAL, |
| 48 base::WaitableEvent::InitialState::NOT_SIGNALED){}; |
| 49 |
| 50 BackgroundLoaderContentsTest::~BackgroundLoaderContentsTest(){}; |
| 51 |
| 52 void BackgroundLoaderContentsTest::SetUp() { |
| 53 contents_.reset(new BackgroundLoaderContents()); |
| 54 download_ = false; |
| 55 } |
| 56 |
| 57 void BackgroundLoaderContentsTest::TearDown() { |
| 58 contents_.reset(); |
| 59 } |
| 60 |
| 61 void BackgroundLoaderContentsTest::DownloadCallback(bool download) { |
| 62 download_ = download; |
| 63 waiter_.Signal(); |
| 64 } |
| 65 |
| 66 void BackgroundLoaderContentsTest::MediaAccessCallback( |
| 67 const content::MediaStreamDevices& devices, |
| 68 content::MediaStreamRequestResult result, |
| 69 std::unique_ptr<content::MediaStreamUI> ui) { |
| 70 devices_ = devices; |
| 71 request_result_ = result; |
| 72 media_stream_ui_.reset(ui.get()); |
| 73 waiter_.Signal(); |
| 74 } |
| 75 |
| 76 TEST_F(BackgroundLoaderContentsTest, NotVisible) { |
| 77 ASSERT_TRUE(contents()->IsNeverVisible(nullptr)); |
| 78 } |
| 79 |
| 80 TEST_F(BackgroundLoaderContentsTest, SuppressDialogs) { |
| 81 ASSERT_TRUE(contents()->ShouldSuppressDialogs(nullptr)); |
| 82 } |
| 83 |
| 84 TEST_F(BackgroundLoaderContentsTest, DoesNotFocusAfterCrash) { |
| 85 ASSERT_FALSE(contents()->ShouldFocusPageAfterCrash()); |
| 86 } |
| 87 |
| 88 TEST_F(BackgroundLoaderContentsTest, CannotDownload) { |
| 89 contents()->CanDownload( |
| 90 GURL::EmptyGURL(), std::string(), |
| 91 base::Bind(&BackgroundLoaderContentsTest::DownloadCallback, |
| 92 base::Unretained(this))); |
| 93 WaitForSignal(); |
| 94 ASSERT_FALSE(download()); |
| 95 } |
| 96 |
| 97 TEST_F(BackgroundLoaderContentsTest, ShouldNotCreateWebContents) { |
| 98 ASSERT_FALSE(contents()->ShouldCreateWebContents( |
| 99 nullptr /* contents */, 0 /* route_id */, 0 /* main_frame_route_id */, |
| 100 0 /* main_frame_widget_route_id */, |
| 101 WINDOW_CONTAINER_TYPE_NORMAL /* window_container_type */, |
| 102 "foo" /* frame_name */, GURL::EmptyGURL() /* target_url */, |
| 103 "bar" /* partition_id */, nullptr /* session_storage_namespace */)); |
| 104 } |
| 105 |
| 106 TEST_F(BackgroundLoaderContentsTest, ShouldNotAddNewContents) { |
| 107 bool blocked; |
| 108 contents()->AddNewContents( |
| 109 nullptr /* source */, nullptr /* new_contents */, |
| 110 WindowOpenDisposition::CURRENT_TAB /* disposition */, |
| 111 gfx::Rect() /* initial_rect */, false /* user_gesture */, |
| 112 &blocked /* was_blocked */); |
| 113 ASSERT_TRUE(blocked); |
| 114 } |
| 115 |
| 116 TEST_F(BackgroundLoaderContentsTest, DoesNotGiveMediaAccessPermission) { |
| 117 content::MediaStreamRequest request( |
| 118 0 /* render_process_id */, 0 /* render_frame_id */, |
| 119 0 /* page_request_id */, GURL::EmptyGURL() /* security_origin */, |
| 120 false /* user_gesture */, |
| 121 content::MediaStreamRequestType::MEDIA_DEVICE_ACCESS /* request_type */, |
| 122 std::string() /* requested_audio_device_id */, |
| 123 std::string() /* requested_video_device_id */, |
| 124 content::MediaStreamType::MEDIA_TAB_AUDIO_CAPTURE /* audio_type */, |
| 125 content::MediaStreamType::MEDIA_TAB_VIDEO_CAPTURE /* video_type */, |
| 126 false /* disable_local_echo */); |
| 127 contents()->RequestMediaAccessPermission( |
| 128 nullptr /* contents */, request /* request */, |
| 129 base::Bind(&BackgroundLoaderContentsTest::MediaAccessCallback, |
| 130 base::Unretained(this))); |
| 131 WaitForSignal(); |
| 132 // No devices allowed. |
| 133 ASSERT_TRUE(devices().empty()); |
| 134 // Permission has been dismissed rather than denied. |
| 135 ASSERT_EQ( |
| 136 content::MediaStreamRequestResult::MEDIA_DEVICE_PERMISSION_DISMISSED, |
| 137 request_result()); |
| 138 ASSERT_EQ(nullptr, media_stream_ui()); |
| 139 } |
| 140 |
| 141 TEST_F(BackgroundLoaderContentsTest, CheckMediaAccessPermissionFalse) { |
| 142 ASSERT_FALSE(contents()->CheckMediaAccessPermission( |
| 143 nullptr /* contents */, GURL::EmptyGURL() /* security_origin */, |
| 144 content::MediaStreamType::MEDIA_TAB_VIDEO_CAPTURE /* type */)); |
| 145 } |
| 146 |
| 147 } // namespace background_loader |
| OLD | NEW |