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
3 // found in the LICENSE file.
5 #include "base/strings/string16.h"
6 #include "base/strings/string_util.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "components/omnibox/browser/omnibox_view.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "testing/platform_test.h"
12 using base::ASCIIToUTF16
;
16 class OmniboxViewTest
: public PlatformTest
{
19 TEST_F(OmniboxViewTest
, TestStripSchemasUnsafeForPaste
) {
20 const char* urls
[] = {
21 "http://www.google.com?q=javascript:alert(0)", // Safe URL.
22 "javAscript:alert(0)", // Unsafe JS URL.
23 "jaVascript:\njavaScript: alert(0)" // Single strip unsafe.
26 const char* expecteds
[] = {
27 "http://www.google.com?q=javascript:alert(0)", // Safe URL.
28 "alert(0)", // Unsafe JS URL.
29 "alert(0)" // Single strip unsafe.
32 for (size_t i
= 0; i
< arraysize(urls
); i
++) {
33 EXPECT_EQ(ASCIIToUTF16(expecteds
[i
]),
34 OmniboxView::StripJavascriptSchemas(ASCIIToUTF16(urls
[i
])));
38 TEST_F(OmniboxViewTest
, SanitizeTextForPaste
) {
39 // Broken URL has newlines stripped.
40 const base::string16
kWrappedURL(ASCIIToUTF16(
41 "http://www.chromium.org/developers/testing/chromium-\n"
42 "build-infrastructure/tour-of-the-chromium-buildbot"));
44 const base::string16
kFixedURL(ASCIIToUTF16(
45 "http://www.chromium.org/developers/testing/chromium-"
46 "build-infrastructure/tour-of-the-chromium-buildbot"));
47 EXPECT_EQ(kFixedURL
, OmniboxView::SanitizeTextForPaste(kWrappedURL
));
49 // Multi-line address is converted to a single-line address.
50 const base::string16
kWrappedAddress(ASCIIToUTF16(
51 "1600 Amphitheatre Parkway\nMountain View, CA"));
53 const base::string16
kFixedAddress(ASCIIToUTF16(
54 "1600 Amphitheatre Parkway Mountain View, CA"));
55 EXPECT_EQ(kFixedAddress
, OmniboxView::SanitizeTextForPaste(kWrappedAddress
));