| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/base/clipboard/clipboard_android.h" | 5 #include "ui/base/clipboard/clipboard_android.h" |
| 6 | 6 |
| 7 #include <string> |
| 8 |
| 7 #include "base/android/context_utils.h" | 9 #include "base/android/context_utils.h" |
| 8 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| 9 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
| 12 #include "base/time/time.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 14 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 12 | 15 |
| 13 namespace ui { | 16 namespace ui { |
| 14 | 17 |
| 15 class ClipboardAndroidTest : public ::testing::Test { | 18 class ClipboardAndroidTest : public ::testing::Test { |
| 16 public: | 19 public: |
| 17 ~ClipboardAndroidTest() override { | 20 ~ClipboardAndroidTest() override { |
| 18 Clipboard::DestroyClipboardForCurrentThread(); | 21 Clipboard::DestroyClipboardForCurrentThread(); |
| 19 }; | 22 }; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 // Make sure some text is available | 81 // Make sure some text is available |
| 79 EXPECT_TRUE(clipboard().IsFormatAvailable( | 82 EXPECT_TRUE(clipboard().IsFormatAvailable( |
| 80 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 83 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 81 | 84 |
| 82 // Make sure the text is what we inserted while simulating the other app | 85 // Make sure the text is what we inserted while simulating the other app |
| 83 std::string contents; | 86 std::string contents; |
| 84 clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &contents); | 87 clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &contents); |
| 85 EXPECT_EQ(contents, new_value); | 88 EXPECT_EQ(contents, new_value); |
| 86 } | 89 } |
| 87 | 90 |
| 91 TEST_F(ClipboardAndroidTest, LastModifiedTimePersists) { |
| 92 // Set up the pref system. *** |
| 93 // 1. Create a TestingPrefServiceSimple (which is a PrefService) |
| 94 // and also use is registry() function. |
| 95 // 2. Call ClipboardAndroid::RegisterPrefs() |
| 96 // 3. Call ClipboardAndroid::SetLocalState() |
| 97 |
| 98 base::Time test_start_time = base::Time::Now(); |
| 99 std::string url = "http://example.com/"; |
| 100 clipboard().WriteText(url.data(), url.length()); |
| 101 base::TimeDelta last_modified_time = clipboard().GetLastModifiedTime(); |
| 102 // It's possible the WriteText() took some time, so allow a little slop |
| 103 // (5 seconds) in this comparison; don't check for equality. |
| 104 EXPECT_GE(last_modified_time, test_start_time); |
| 105 EXPECT_LE(last_modified_time, |
| 106 test_start_time + base::TimeDelta::FromSeconds(5)); |
| 107 |
| 108 // *** Force writing the prefs / storing them, if necessary. |
| 109 |
| 110 // Destroy the clipboard and make sure the information persists. (It's be |
| 111 // implicitly recreated when accessed.) |
| 112 Clipboard::DestroyClipboardForCurrentThread(); |
| 113 |
| 114 // *** |
| 115 // Check that the last modified time hasn't changed from the last time |
| 116 // we read it. |
| 117 } |
| 118 |
| 88 } // namespace ui | 119 } // namespace ui |
| 89 | 120 |
| 90 #include "ui/base/clipboard/clipboard_test_template.h" | 121 #include "ui/base/clipboard/clipboard_test_template.h" |
| OLD | NEW |