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

Side by Side 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, 9 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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/open_from_clipboard/clipboard_recent_content_ios.h"
6
7 #import <UIKit/UIKit.h>
8
9 #include "base/memory/scoped_ptr.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace test {
13 class ClipboardRecentContentIOSTestHelper : public ClipboardRecentContentIOS {
14 public:
15 ClipboardRecentContentIOSTestHelper(){};
sdefresne 2015/02/26 16:36:00 no ";" after {}, space before (everywhere)
jif 2015/03/03 14:37:59 Done.
16 ~ClipboardRecentContentIOSTestHelper() override{};
17 void SetStoredPasteboardChangeDate(NSDate* changeDate) {
18 lastPasteboardChangeDate_.reset([changeDate copy]);
19 SaveToUserDefaults();
20 }
21 };
22 }
sdefresne 2015/02/26 16:36:00 } // namespace test
jif 2015/03/03 14:37:59 Done.
23
24 namespace {
25 void SetPasteboardContent(const char* data) {
26 [[UIPasteboard generalPasteboard]
27 setValue:[NSString stringWithUTF8String:data]
28 forPasteboardType:@"public.plain-text"];
29 }
30 const char* kUnrecognizedURL = "ftp://foo/";
31 const char* kRecognizedURL = "http://bar/";
32 const char* kAppSpecificURL = "test://qux/";
33 const char* kAppSpecificScheme = "test";
34 NSTimeInterval kSevenHours = 60 * 60 * 7;
35 }
sdefresne 2015/02/26 16:36:00 } // namespace
jif 2015/03/03 14:37:59 Done.
36
37 class ClipboardRecentContentIOSTest : public ::testing::Test {
38 protected:
39 void SetUp() override {
40 clipboardContent_.reset(new test::ClipboardRecentContentIOSTestHelper());
41 }
42 void TearDown() override {}
43 protected:
44 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.
45 };
46
47 TEST_F(ClipboardRecentContentIOSTest, SchemeFiltering) {
48 GURL gurl;
49
50 // checks that the test is ran. Ignore during code review.
51 EXPECT_TRUE(false);
52
53
54 // Test unrecognized URL.
55 SetPasteboardContent(kUnrecognizedURL);
56 EXPECT_FALSE(clipboardContent_->GetRecentURLFromClipboard(&gurl));
57
58 // Test recognized URL.
59 SetPasteboardContent(kRecognizedURL);
60 EXPECT_TRUE(clipboardContent_->GetRecentURLFromClipboard(&gurl));
61 EXPECT_STREQ(kRecognizedURL, gurl.spec().c_str());
62
63 // Test URL with app specific scheme, before and after configuration.
64 SetPasteboardContent(kAppSpecificURL);
65 EXPECT_FALSE(clipboardContent_->GetRecentURLFromClipboard(&gurl));
66 clipboardContent_->set_application_scheme(kAppSpecificScheme);
67 SetPasteboardContent(kAppSpecificURL);
68 EXPECT_TRUE(clipboardContent_->GetRecentURLFromClipboard(&gurl));
69 EXPECT_STREQ(kAppSpecificURL, gurl.spec().c_str());
70 }
71
72 TEST_F(ClipboardRecentContentIOSTest, PasteboardURLObsolescence) {
73 GURL gurl;
74 SetPasteboardContent(kRecognizedURL);
75
76 // Test that recent pasteboard data is provided.
77 EXPECT_TRUE(clipboardContent_->GetRecentURLFromClipboard(&gurl));
78 EXPECT_STREQ(kRecognizedURL, gurl.spec().c_str());
79
80 // Test that old pasteboard data is not provided.
81 clipboardContent_->SetStoredPasteboardChangeDate(
82 [NSDate dateWithTimeIntervalSinceNow:-kSevenHours]);
83 EXPECT_FALSE(clipboardContent_->GetRecentURLFromClipboard(&gurl));
84
85 // Test that pasteboard data is treated as new if the last recorded clipboard
86 // change dates from before the machine booted.
87 clipboardContent_->SetStoredPasteboardChangeDate(
88 [NSDate dateWithTimeIntervalSince1970:0]);
89 clipboardContent_.reset(new test::ClipboardRecentContentIOSTestHelper());
90 EXPECT_TRUE(clipboardContent_->GetRecentURLFromClipboard(&gurl));
91 EXPECT_STREQ(kRecognizedURL, gurl.spec().c_str());
92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698