OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/omnibox/omnibox_view.h" | 5 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 "alert(0)", // Unsafe JS URL. | 37 "alert(0)", // Unsafe JS URL. |
38 "alert(0)" // Single strip unsafe. | 38 "alert(0)" // Single strip unsafe. |
39 }; | 39 }; |
40 | 40 |
41 for (size_t i = 0; i < arraysize(urls); i++) { | 41 for (size_t i = 0; i < arraysize(urls); i++) { |
42 EXPECT_EQ(ASCIIToUTF16(expecteds[i]), | 42 EXPECT_EQ(ASCIIToUTF16(expecteds[i]), |
43 OmniboxView::StripJavascriptSchemas(ASCIIToUTF16(urls[i]))); | 43 OmniboxView::StripJavascriptSchemas(ASCIIToUTF16(urls[i]))); |
44 } | 44 } |
45 } | 45 } |
46 | 46 |
| 47 TEST_F(OmniboxViewTest, SanitizeTextForPaste) { |
| 48 // Broken URL has newlines stripped. |
| 49 const string16 kWrappedURL(ASCIIToUTF16( |
| 50 "http://www.chromium.org/developers/testing/chromium-\n" |
| 51 "build-infrastructure/tour-of-the-chromium-buildbot")); |
| 52 |
| 53 const string16 kFixedURL(ASCIIToUTF16( |
| 54 "http://www.chromium.org/developers/testing/chromium-" |
| 55 "build-infrastructure/tour-of-the-chromium-buildbot")); |
| 56 EXPECT_EQ(kFixedURL, OmniboxView::SanitizeTextForPaste(kWrappedURL)); |
| 57 |
| 58 // Multi-line address is converted to a single-line address. |
| 59 const string16 kWrappedAddress(ASCIIToUTF16( |
| 60 "1600 Amphitheatre Parkway\nMountain View, CA")); |
| 61 |
| 62 const string16 kFixedAddress(ASCIIToUTF16( |
| 63 "1600 Amphitheatre Parkway Mountain View, CA")); |
| 64 EXPECT_EQ(kFixedAddress, OmniboxView::SanitizeTextForPaste(kWrappedAddress)); |
| 65 } |
| 66 |
47 TEST_F(OmniboxViewTest, GetClipboardText) { | 67 TEST_F(OmniboxViewTest, GetClipboardText) { |
48 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); | 68 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); |
49 | 69 |
50 const string16 kPlainText(ASCIIToUTF16("test text")); | 70 const string16 kPlainText(ASCIIToUTF16("test text")); |
51 const std::string kURL("http://www.example.com/"); | 71 const std::string kURL("http://www.example.com/"); |
52 | 72 |
53 // Can we pull straight text off the clipboard? | 73 // Can we pull straight text off the clipboard? |
54 { | 74 { |
55 ui::ScopedClipboardWriter clipboard_writer(clipboard, | 75 ui::ScopedClipboardWriter clipboard_writer(clipboard, |
56 ui::Clipboard::BUFFER_STANDARD); | 76 ui::Clipboard::BUFFER_STANDARD); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 #endif | 120 #endif |
101 | 121 |
102 // Do we get nothing if there is neither text nor a bookmark? | 122 // Do we get nothing if there is neither text nor a bookmark? |
103 { | 123 { |
104 const string16 kMarkup(ASCIIToUTF16("<strong>Hi!</string>")); | 124 const string16 kMarkup(ASCIIToUTF16("<strong>Hi!</string>")); |
105 ui::ScopedClipboardWriter clipboard_writer(clipboard, | 125 ui::ScopedClipboardWriter clipboard_writer(clipboard, |
106 ui::Clipboard::BUFFER_STANDARD); | 126 ui::Clipboard::BUFFER_STANDARD); |
107 clipboard_writer.WriteHTML(kMarkup, kURL); | 127 clipboard_writer.WriteHTML(kMarkup, kURL); |
108 } | 128 } |
109 EXPECT_TRUE(OmniboxView::GetClipboardText().empty()); | 129 EXPECT_TRUE(OmniboxView::GetClipboardText().empty()); |
110 | |
111 // Broken URL has newlines stripped. | |
112 { | |
113 const string16 kWrappedURL(ASCIIToUTF16( | |
114 "http://www.chromium.org/developers/testing/chromium-\n" | |
115 "build-infrastructure/tour-of-the-chromium-buildbot")); | |
116 ui::ScopedClipboardWriter clipboard_writer(clipboard, | |
117 ui::Clipboard::BUFFER_STANDARD); | |
118 clipboard_writer.WriteText(kWrappedURL); | |
119 } | |
120 | |
121 const string16 kFixedURL(ASCIIToUTF16( | |
122 "http://www.chromium.org/developers/testing/chromium-" | |
123 "build-infrastructure/tour-of-the-chromium-buildbot")); | |
124 EXPECT_EQ(kFixedURL, OmniboxView::GetClipboardText()); | |
125 | |
126 // Multi-line address is converted to a single-line address. | |
127 { | |
128 const string16 kWrappedAddress(ASCIIToUTF16( | |
129 "1600 Amphitheatre Parkway\nMountain View, CA")); | |
130 ui::ScopedClipboardWriter clipboard_writer(clipboard, | |
131 ui::Clipboard::BUFFER_STANDARD); | |
132 clipboard_writer.WriteText(kWrappedAddress); | |
133 } | |
134 | |
135 const string16 kFixedAddress(ASCIIToUTF16( | |
136 "1600 Amphitheatre Parkway Mountain View, CA")); | |
137 EXPECT_EQ(kFixedAddress, OmniboxView::GetClipboardText()); | |
138 } | 130 } |
139 | 131 |
140 } // namespace | 132 } // namespace |
OLD | NEW |