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

Unified Diff: components/open_from_clipboard/clipboard_recent_content_ios_unittest.mm

Issue 1274713003: Refactor ClipboardRecentContent singleton creation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comment by jif Created 5 years, 4 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
« no previous file with comments | « components/open_from_clipboard/clipboard_recent_content_ios.mm ('k') | ios/chrome/browser/DEPS » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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));
« no previous file with comments | « components/open_from_clipboard/clipboard_recent_content_ios.mm ('k') | ios/chrome/browser/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698