1// Copyright (c) 2011 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. 4 5#include "chrome/browser/themes/theme_service.h" 6 7#include "base/json/json_reader.h" 8#include "testing/gtest/include/gtest/gtest.h" 9 10TEST(ThemeServiceTest, AlignmentConversion) { 11 // Verify that we get out what we put in. 12 std::string top_left = "top left"; 13 int alignment = ThemeService::StringToAlignment(top_left); 14 EXPECT_EQ(ThemeService::ALIGN_TOP | ThemeService::ALIGN_LEFT, 15 alignment); 16 EXPECT_EQ(top_left, ThemeService::AlignmentToString(alignment)); 17 18 alignment = ThemeService::StringToAlignment("top"); 19 EXPECT_EQ(ThemeService::ALIGN_TOP, alignment); 20 EXPECT_EQ("top", ThemeService::AlignmentToString(alignment)); 21 22 alignment = ThemeService::StringToAlignment("left"); 23 EXPECT_EQ(ThemeService::ALIGN_LEFT, alignment); 24 EXPECT_EQ("left", ThemeService::AlignmentToString(alignment)); 25 26 alignment = ThemeService::StringToAlignment("right"); 27 EXPECT_EQ(ThemeService::ALIGN_RIGHT, alignment); 28 EXPECT_EQ("right", ThemeService::AlignmentToString(alignment)); 29 30 alignment = ThemeService::StringToAlignment("righttopbottom"); 31 EXPECT_EQ(ThemeService::ALIGN_CENTER, alignment); 32 EXPECT_EQ("", ThemeService::AlignmentToString(alignment)); 33} 34 35TEST(ThemeServiceTest, AlignmentConversionInput) { 36 // Verify that we output in an expected format. 37 int alignment = ThemeService::StringToAlignment("right bottom"); 38 EXPECT_EQ("bottom right", ThemeService::AlignmentToString(alignment)); 39 40 // Verify that bad strings don't cause explosions. 41 alignment = ThemeService::StringToAlignment("new zealand"); 42 EXPECT_EQ("", ThemeService::AlignmentToString(alignment)); 43 44 // Verify that bad strings don't cause explosions. 45 alignment = ThemeService::StringToAlignment("new zealand top"); 46 EXPECT_EQ("top", ThemeService::AlignmentToString(alignment)); 47 48 // Verify that bad strings don't cause explosions. 49 alignment = ThemeService::StringToAlignment("new zealandtop"); 50 EXPECT_EQ("", ThemeService::AlignmentToString(alignment)); 51} 52