Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Unified Diff: ios/chrome/browser/ui/activity_services/chrome_activity_item_thumbnail_generator_unittest.mm

Issue 2645653003: Expose thumbnails of pages to iOS share extensions. (Closed)
Patch Set: Addressed comments. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/activity_services/chrome_activity_item_thumbnail_generator_unittest.mm
diff --git a/ios/chrome/browser/ui/activity_services/chrome_activity_item_thumbnail_generator_unittest.mm b/ios/chrome/browser/ui/activity_services/chrome_activity_item_thumbnail_generator_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..df3dbca03d78228fd67095391960f5273c39c971
--- /dev/null
+++ b/ios/chrome/browser/ui/activity_services/chrome_activity_item_thumbnail_generator_unittest.mm
@@ -0,0 +1,62 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/chrome/browser/ui/activity_services/chrome_activity_item_thumbnail_generator.h"
+
+#include "base/mac/scoped_nsobject.h"
+#import "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
+#include "ios/chrome/browser/tabs/tab.h"
+#include "testing/platform_test.h"
+#import "third_party/ocmock/OCMock/OCMock.h"
+#include "ui/base/test/ios/ui_image_test_utils.h"
+
+namespace {
+
+class ChromeActivityItemThumbnailGeneratorTest : public PlatformTest {
+ protected:
+ void SetUp() override {
+ tab_.reset([[OCMockObject niceMockForClass:[Tab class]] retain]);
+
+ UIImage* snapshot = ui::test::uiimage_utils::UIImageWithSizeAndSolidColor(
+ CGSizeMake(400, 300), [UIColor redColor]);
+
+ [[[tab_ stub] andReturn:snapshot] generateSnapshotWithOverlay:NO
+ visibleFrameOnly:YES];
+ }
+
+ void SetBrowserStateOnTab(bool incognito) {
+ TestChromeBrowserState::Builder test_cbs_builder;
+ chrome_browser_state_ = test_cbs_builder.Build();
+ ios::ChromeBrowserState* browserState =
+ incognito ? chrome_browser_state_->GetOffTheRecordChromeBrowserState()
+ : chrome_browser_state_.get();
+ [[[tab_ stub] andReturnValue:OCMOCK_VALUE(browserState)] browserState];
+ }
+
+ std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
+ base::scoped_nsobject<id> tab_;
+};
+
+TEST_F(ChromeActivityItemThumbnailGeneratorTest, ThumbnailForNonIncognitoTab) {
+ SetBrowserStateOnTab(false);
+ CGSize size = CGSizeMake(50, 50);
+ ThumbnailGeneratorBlock generatorBlock =
+ activity_services::ThumbnailGeneratorForTab(tab_);
+ EXPECT_TRUE(generatorBlock);
+ UIImage* thumbnail = generatorBlock(size);
+ EXPECT_TRUE(thumbnail);
+ EXPECT_TRUE(CGSizeEqualToSize(thumbnail.size, size));
+}
+
+TEST_F(ChromeActivityItemThumbnailGeneratorTest, NoThumbnailForIncognitoTab) {
+ SetBrowserStateOnTab(true);
+ CGSize size = CGSizeMake(50, 50);
+ ThumbnailGeneratorBlock generatorBlock =
+ activity_services::ThumbnailGeneratorForTab(tab_);
+ EXPECT_TRUE(generatorBlock);
+ UIImage* thumbnail = generatorBlock(size);
+ EXPECT_FALSE(thumbnail);
+}
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698