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

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, fixed tests. 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..3e4b32c80749e6d1324dd50b552eed8356e0f064
--- /dev/null
+++ b/ios/chrome/browser/ui/activity_services/chrome_activity_item_thumbnail_generator_unittest.mm
@@ -0,0 +1,65 @@
+// 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"
+
+namespace {
+
+class ChromeActivityItemThumbnailGeneratorTest : public PlatformTest {
+ protected:
+ void SetUp() override {
+ tab_.reset([[OCMockObject niceMockForClass:[Tab class]] retain]);
+
+ CGRect rect = CGRectMake(0, 0, 400, 300);
+ UIGraphicsBeginImageContext(rect.size);
+ CGContextRef context = UIGraphicsGetCurrentContext();
+ CGContextSetFillColorWithColor(context, [[UIColor redColor] CGColor]);
+ CGContextFillRect(context, rect);
+ UIImage* snapshot = UIGraphicsGetImageFromCurrentImageContext();
+ UIGraphicsEndImageContext();
+ [[[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