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 |
index c95602352f44e19034f0e873eb2527b204241693..6fbb0ee3e0db46607b96bc1063775f086320eda1 100644 |
--- a/components/open_from_clipboard/clipboard_recent_content_ios_unittest.mm |
+++ b/components/open_from_clipboard/clipboard_recent_content_ios_unittest.mm |
@@ -11,56 +11,52 @@ |
#include "testing/gtest/include/gtest/gtest.h" |
#include "testing/platform_test.h" |
-namespace test { |
-class ClipboardRecentContentIOSTestHelper : public ClipboardRecentContentIOS { |
- public: |
- // By default, set that the device booted 10 days ago. |
- ClipboardRecentContentIOSTestHelper() |
- : ClipboardRecentContentIOS(base::TimeDelta::FromDays(10)) {} |
- ClipboardRecentContentIOSTestHelper(base::TimeDelta t) |
- : ClipboardRecentContentIOS(t) {} |
- |
- ~ClipboardRecentContentIOSTestHelper() override {} |
- void SetStoredPasteboardChangeDate(NSDate* changeDate) { |
- lastPasteboardChangeDate_.reset([changeDate copy]); |
- SaveToUserDefaults(); |
- } |
- void SetStoredPasteboardChangeCount(NSInteger newChangeCount) { |
- lastPasteboardChangeCount_ = newChangeCount; |
- SaveToUserDefaults(); |
- } |
-}; |
-} // namespace test |
- |
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"; |
+const char kUnrecognizedURL[] = "ftp://foo/"; |
+const char kRecognizedURL[] = "http://bar/"; |
+const char kAppSpecificURL[] = "test://qux/"; |
+const char kAppSpecificScheme[] = "test"; |
NSTimeInterval kSevenHours = 60 * 60 * 7; |
} // namespace |
class ClipboardRecentContentIOSTest : public ::testing::Test { |
protected: |
- void SetUp() override { |
- clipboard_content_.reset(new test::ClipboardRecentContentIOSTestHelper()); |
+ ClipboardRecentContentIOSTest() { |
+ // By default, set that the device booted 10 days ago. |
+ ResetClipboardRecentContent(kAppSpecificScheme, |
+ base::TimeDelta::FromDays(10)); |
} |
- void TearDown() override {} |
void SimulateDeviceRestart() { |
// TODO(jif): Simulates the fact that on iOS7, the pasteboard's changeCount |
// is reset. http://crbug.com/503609 |
- clipboard_content_.reset(new test::ClipboardRecentContentIOSTestHelper( |
- base::TimeDelta::FromSeconds(0))); |
+ ResetClipboardRecentContent(kAppSpecificScheme, |
+ base::TimeDelta::FromSeconds(0)); |
+ } |
+ |
+ void ResetClipboardRecentContent(const std::string& application_scheme, |
+ base::TimeDelta time_delta) { |
+ clipboard_content_.reset( |
+ new ClipboardRecentContentIOS(application_scheme, time_delta)); |
+ } |
+ |
+ void SetStoredPasteboardChangeDate(NSDate* changeDate) { |
+ clipboard_content_->lastPasteboardChangeDate_.reset([changeDate copy]); |
+ clipboard_content_->SaveToUserDefaults(); |
+ } |
+ |
+ void SetStoredPasteboardChangeCount(NSInteger newChangeCount) { |
+ clipboard_content_->lastPasteboardChangeCount_ = newChangeCount; |
+ clipboard_content_->SaveToUserDefaults(); |
} |
protected: |
- scoped_ptr<test::ClipboardRecentContentIOSTestHelper> clipboard_content_; |
+ scoped_ptr<ClipboardRecentContentIOS> clipboard_content_; |
}; |
TEST_F(ClipboardRecentContentIOSTest, SchemeFiltering) { |
@@ -75,13 +71,16 @@ TEST_F(ClipboardRecentContentIOSTest, SchemeFiltering) { |
EXPECT_TRUE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); |
EXPECT_STREQ(kRecognizedURL, gurl.spec().c_str()); |
- // Test URL with app specific scheme, before and after configuration. |
- SetPasteboardContent(kAppSpecificURL); |
- EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); |
- clipboard_content_->set_application_scheme(kAppSpecificScheme); |
+ // Test URL with app specific scheme. |
SetPasteboardContent(kAppSpecificURL); |
EXPECT_TRUE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); |
EXPECT_STREQ(kAppSpecificURL, gurl.spec().c_str()); |
+ |
+ // Test URL without app specific scheme. |
+ ResetClipboardRecentContent(std::string(), base::TimeDelta::FromDays(10)); |
+ |
+ SetPasteboardContent(kAppSpecificURL); |
+ EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); |
} |
TEST_F(ClipboardRecentContentIOSTest, PasteboardURLObsolescence) { |
@@ -93,16 +92,16 @@ TEST_F(ClipboardRecentContentIOSTest, PasteboardURLObsolescence) { |
EXPECT_STREQ(kRecognizedURL, gurl.spec().c_str()); |
// Test that old pasteboard data is not provided. |
- clipboard_content_->SetStoredPasteboardChangeDate( |
+ SetStoredPasteboardChangeDate( |
[NSDate dateWithTimeIntervalSinceNow:-kSevenHours]); |
EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); |
// Tests that if chrome is relaunched, old pasteboard data is still |
// not provided. |
- clipboard_content_.reset(new test::ClipboardRecentContentIOSTestHelper()); |
+ ResetClipboardRecentContent(kAppSpecificScheme, |
+ base::TimeDelta::FromDays(10)); |
EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); |
- |
SimulateDeviceRestart(); |
if (base::ios::IsRunningOnIOS8OrLater()) { |
// Tests that if the device is restarted, old pasteboard data is still |
@@ -129,7 +128,8 @@ TEST_F(ClipboardRecentContentIOSTest, SupressedPasteboard) { |
EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); |
// Create a new clipboard content to test persistence. |
- clipboard_content_.reset(new test::ClipboardRecentContentIOSTestHelper()); |
+ ResetClipboardRecentContent(kAppSpecificScheme, |
+ base::TimeDelta::FromDays(10)); |
// Check that the pasteboard content is still suppressed. |
EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); |