| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #include "platform/clipboard/ClipboardUtilities.h" | |
| 32 | |
| 33 #include "testing/gtest/include/gtest/gtest.h" | |
| 34 #include "wtf/StdLibExtras.h" | |
| 35 #include "wtf/text/WTFString.h" | |
| 36 | |
| 37 namespace blink { | |
| 38 | |
| 39 #if OS(WIN) | |
| 40 const char invalidCharacters[] = "\x00/\\:*?\"<>|"; | |
| 41 #else | |
| 42 const char invalidCharacters[] = | |
| 43 "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" | |
| 44 "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" | |
| 45 "\x7f/"; | |
| 46 #endif | |
| 47 const char longString[] = | |
| 48 "0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765," | |
| 49 "10946,17711,28657,46368," | |
| 50 "75025,121393,196418,317811,514229,832040,1346269,2178309,3524578,5702887," | |
| 51 "9227465,14930352"; | |
| 52 | |
| 53 TEST(ClipboardUtilitiesTest, Normal) { | |
| 54 String name = "name"; | |
| 55 String extension = "ext"; | |
| 56 validateFilename(name, extension); | |
| 57 EXPECT_EQ("name", name); | |
| 58 EXPECT_EQ("ext", extension); | |
| 59 } | |
| 60 | |
| 61 TEST(ClipboardUtilitiesTest, InvalidCharacters) { | |
| 62 String name = "na" + | |
| 63 String(invalidCharacters, WTF_ARRAY_LENGTH(invalidCharacters)) + | |
| 64 "me"; | |
| 65 String extension = | |
| 66 "e" + String(invalidCharacters, WTF_ARRAY_LENGTH(invalidCharacters)) + | |
| 67 "xt"; | |
| 68 validateFilename(name, extension); | |
| 69 EXPECT_EQ("name", name); | |
| 70 EXPECT_EQ("ext", extension); | |
| 71 } | |
| 72 | |
| 73 TEST(ClipboardUtilitiesTest, ExtensionTooLong) { | |
| 74 String name; | |
| 75 String extension = String(longString) + longString; | |
| 76 validateFilename(name, extension); | |
| 77 EXPECT_EQ(String(), extension); | |
| 78 } | |
| 79 | |
| 80 TEST(ClipboardUtilitiesTest, NamePlusExtensionTooLong) { | |
| 81 String name = String(longString) + longString; | |
| 82 String extension = longString; | |
| 83 validateFilename(name, extension); | |
| 84 EXPECT_EQ( | |
| 85 "0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765," | |
| 86 "109", | |
| 87 name); | |
| 88 EXPECT_EQ(longString, extension); | |
| 89 EXPECT_EQ(254u, name.length() + extension.length()); | |
| 90 } | |
| 91 | |
| 92 } // namespace blink | |
| OLD | NEW |