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

Unified Diff: components/open_from_clipboard/clipboard_recent_content_ios_unittest.mm

Issue 961673004: Add unittest to Open from Clipboard component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added error to check that the test is ran. Created 5 years, 10 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: components/open_from_clipboard/clipboard_recent_content_ios_unittest.mm
diff --git a/components/open_from_clipboard/clipboard_recent_content_ios_unittest.mm b/components/open_from_clipboard/clipboard_recent_content_ios_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..50a54a2fa53137d21e41ab9e19b34cfeb59d2b40
--- /dev/null
+++ b/components/open_from_clipboard/clipboard_recent_content_ios_unittest.mm
@@ -0,0 +1,92 @@
+// Copyright 2015 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.
+
+#include "components/open_from_clipboard/clipboard_recent_content_ios.h"
+
+#import <UIKit/UIKit.h>
+
+#include "base/memory/scoped_ptr.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace test {
+class ClipboardRecentContentIOSTestHelper : public ClipboardRecentContentIOS {
+ public:
+ ClipboardRecentContentIOSTestHelper(){};
sdefresne 2015/02/26 16:36:00 no ";" after {}, space before (everywhere)
jif 2015/03/03 14:37:59 Done.
+ ~ClipboardRecentContentIOSTestHelper() override{};
+ void SetStoredPasteboardChangeDate(NSDate* changeDate) {
+ lastPasteboardChangeDate_.reset([changeDate copy]);
+ SaveToUserDefaults();
+ }
+};
+}
sdefresne 2015/02/26 16:36:00 } // namespace test
jif 2015/03/03 14:37:59 Done.
+
+namespace {
+void SetPasteboardContent(const char* data) {
+ [[UIPasteboard generalPasteboard]
+ setValue:[NSString stringWithUTF8String:data]
+ forPasteboardType:@"public.plain-text"];
+}
+const char* kUnrecognizedURL = "ftp://foo/";
+const char* kRecognizedURL = "http://bar/";
+const char* kAppSpecificURL = "test://qux/";
+const char* kAppSpecificScheme = "test";
+NSTimeInterval kSevenHours = 60 * 60 * 7;
+}
sdefresne 2015/02/26 16:36:00 } // namespace
jif 2015/03/03 14:37:59 Done.
+
+class ClipboardRecentContentIOSTest : public ::testing::Test {
+ protected:
+ void SetUp() override {
+ clipboardContent_.reset(new test::ClipboardRecentContentIOSTestHelper());
+ }
+ void TearDown() override {}
+ protected:
+ scoped_ptr<test::ClipboardRecentContentIOSTestHelper> clipboardContent_;
sdefresne 2015/02/26 16:36:00 The style guide is to use _clipboardContent for Ob
jif 2015/03/03 14:37:59 Done.
+};
+
+TEST_F(ClipboardRecentContentIOSTest, SchemeFiltering) {
+ GURL gurl;
+
+ // checks that the test is ran. Ignore during code review.
+ EXPECT_TRUE(false);
+
+
+ // Test unrecognized URL.
+ SetPasteboardContent(kUnrecognizedURL);
+ EXPECT_FALSE(clipboardContent_->GetRecentURLFromClipboard(&gurl));
+
+ // Test recognized URL.
+ SetPasteboardContent(kRecognizedURL);
+ EXPECT_TRUE(clipboardContent_->GetRecentURLFromClipboard(&gurl));
+ EXPECT_STREQ(kRecognizedURL, gurl.spec().c_str());
+
+ // Test URL with app specific scheme, before and after configuration.
+ SetPasteboardContent(kAppSpecificURL);
+ EXPECT_FALSE(clipboardContent_->GetRecentURLFromClipboard(&gurl));
+ clipboardContent_->set_application_scheme(kAppSpecificScheme);
+ SetPasteboardContent(kAppSpecificURL);
+ EXPECT_TRUE(clipboardContent_->GetRecentURLFromClipboard(&gurl));
+ EXPECT_STREQ(kAppSpecificURL, gurl.spec().c_str());
+}
+
+TEST_F(ClipboardRecentContentIOSTest, PasteboardURLObsolescence) {
+ GURL gurl;
+ SetPasteboardContent(kRecognizedURL);
+
+ // Test that recent pasteboard data is provided.
+ EXPECT_TRUE(clipboardContent_->GetRecentURLFromClipboard(&gurl));
+ EXPECT_STREQ(kRecognizedURL, gurl.spec().c_str());
+
+ // Test that old pasteboard data is not provided.
+ clipboardContent_->SetStoredPasteboardChangeDate(
+ [NSDate dateWithTimeIntervalSinceNow:-kSevenHours]);
+ EXPECT_FALSE(clipboardContent_->GetRecentURLFromClipboard(&gurl));
+
+ // Test that pasteboard data is treated as new if the last recorded clipboard
+ // change dates from before the machine booted.
+ clipboardContent_->SetStoredPasteboardChangeDate(
+ [NSDate dateWithTimeIntervalSince1970:0]);
+ clipboardContent_.reset(new test::ClipboardRecentContentIOSTestHelper());
+ EXPECT_TRUE(clipboardContent_->GetRecentURLFromClipboard(&gurl));
+ EXPECT_STREQ(kRecognizedURL, gurl.spec().c_str());
+}

Powered by Google App Engine
This is Rietveld 408576698