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

Unified Diff: chrome/browser/ui/omnibox/omnibox_view_unittest.cc

Issue 7585016: Add unit test for javascript: URL stripping (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 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 | « no previous file | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/omnibox/omnibox_view_unittest.cc
===================================================================
--- chrome/browser/ui/omnibox/omnibox_view_unittest.cc (revision 0)
+++ chrome/browser/ui/omnibox/omnibox_view_unittest.cc (revision 0)
@@ -0,0 +1,31 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/omnibox/omnibox_view.h"
+#include "base/string16.h"
+#include "base/string_util.h"
+#include "base/utf_string_conversions.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+TEST(OmniboxView, TestStripSchemasUnsafeForPaste) {
+
Peter Kasting 2011/08/05 20:10:22 Nit: Extra newline
Tom Sepez 2011/08/05 20:26:09 Done.
+ const char* urls[] = {
+ "http://www.google.com?q=javascript:alert(0)", // Safe URL.
+ "javAscript:alert(0)", // Unsafe JS URL.
Peter Kasting 2011/08/05 20:10:22 Can you also add one more like: " jav\nascript:
Tom Sepez 2011/08/05 20:26:09 Flunks. The compaction occurs above this method.
Peter Kasting 2011/08/05 20:28:18 Ah, I see. Nah, just leave this testcase out.
+ "jaVascript:\njavaScript: alert(0)", // Single strip unsafe.
+ };
+
+ const char* expecteds[] = {
+ "http://www.google.com?q=javascript:alert(0)", // Safe URL.
+ "alert(0)", // Unsafe JS URL.
+ "alert(0)", // Single strip unsafe.
+ };
+
+ for (size_t i = 0; i < arraysize(urls); i++) {
+ string16 url = ASCIIToUTF16(urls[i]);
Peter Kasting 2011/08/05 20:10:22 Nit: I'd probably roll at least these first two di
Tom Sepez 2011/08/05 20:26:09 Done.
+ string16 expected = ASCIIToUTF16(expecteds[i]);
+ string16 result = OmniboxView::StripJavascriptSchemas(url);
+ EXPECT_EQ(expected, result);
+ }
+}
Property changes on: chrome/browser/ui/omnibox/omnibox_view_unittest.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698