| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/encoding_menu_controller.h" | 5 #include "chrome/browser/encoding_menu_controller.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 controller.GetEncodingMenuItems(&profile_en, &english_items); | 51 controller.GetEncodingMenuItems(&profile_en, &english_items); |
| 52 | 52 |
| 53 // Make sure there are items in the lists. | 53 // Make sure there are items in the lists. |
| 54 ASSERT_TRUE(english_items.size() > 0); | 54 ASSERT_TRUE(english_items.size() > 0); |
| 55 // Make sure that autodetect is the first item on both menus | 55 // Make sure that autodetect is the first item on both menus |
| 56 ASSERT_EQ(english_items[0].first, IDC_ENCODING_AUTO_DETECT); | 56 ASSERT_EQ(english_items[0].first, IDC_ENCODING_AUTO_DETECT); |
| 57 } | 57 } |
| 58 | 58 |
| 59 TEST_F(EncodingMenuControllerTest, IsItemChecked) { | 59 TEST_F(EncodingMenuControllerTest, IsItemChecked) { |
| 60 TestingProfile profile_en; | 60 TestingProfile profile_en; |
| 61 std::wstring encoding(L"UTF-8"); | 61 std::string encoding("UTF-8"); |
| 62 | 62 |
| 63 // Check that enabling and disabling autodetect works. | 63 // Check that enabling and disabling autodetect works. |
| 64 bool autodetect_enabed[] = {true, false}; | 64 bool autodetect_enabed[] = {true, false}; |
| 65 PrefService* prefs = profile_en.GetPrefs(); | 65 PrefService* prefs = profile_en.GetPrefs(); |
| 66 EncodingMenuController controller; | 66 EncodingMenuController controller; |
| 67 for (size_t i = 0; i < arraysize(autodetect_enabed); ++i) { | 67 for (size_t i = 0; i < arraysize(autodetect_enabed); ++i) { |
| 68 bool enabled = autodetect_enabed[i]; | 68 bool enabled = autodetect_enabed[i]; |
| 69 prefs->SetBoolean(prefs::kWebKitUsesUniversalDetector, enabled); | 69 prefs->SetBoolean(prefs::kWebKitUsesUniversalDetector, enabled); |
| 70 ASSERT_TRUE(controller.IsItemChecked(&profile_en, | 70 ASSERT_TRUE(controller.IsItemChecked(&profile_en, |
| 71 encoding, | 71 encoding, |
| 72 IDC_ENCODING_AUTO_DETECT) == enabled); | 72 IDC_ENCODING_AUTO_DETECT) == enabled); |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Check all valid encodings, make sure only one is enabled when autodetection | 75 // Check all valid encodings, make sure only one is enabled when autodetection |
| 76 // is turned off. | 76 // is turned off. |
| 77 prefs->SetBoolean(prefs::kWebKitUsesUniversalDetector, false); | 77 prefs->SetBoolean(prefs::kWebKitUsesUniversalDetector, false); |
| 78 bool encoding_is_enabled = false; | 78 bool encoding_is_enabled = false; |
| 79 size_t num_valid_encoding_ids = controller.NumValidGUIEncodingIDs(); | 79 size_t num_valid_encoding_ids = controller.NumValidGUIEncodingIDs(); |
| 80 const int* valid_encodings = controller.ValidGUIEncodingIDs(); | 80 const int* valid_encodings = controller.ValidGUIEncodingIDs(); |
| 81 for (size_t i = 0; i < num_valid_encoding_ids; ++i) { | 81 for (size_t i = 0; i < num_valid_encoding_ids; ++i) { |
| 82 bool on = controller.IsItemChecked(&profile_en, | 82 bool on = controller.IsItemChecked(&profile_en, |
| 83 encoding, | 83 encoding, |
| 84 valid_encodings[i]); | 84 valid_encodings[i]); |
| 85 // Only one item in the encoding menu can be selected at a time. | 85 // Only one item in the encoding menu can be selected at a time. |
| 86 ASSERT_FALSE(on && encoding_is_enabled); | 86 ASSERT_FALSE(on && encoding_is_enabled); |
| 87 encoding_is_enabled |= on; | 87 encoding_is_enabled |= on; |
| 88 } | 88 } |
| 89 | 89 |
| 90 // Make sure at least one encoding is enabled. | 90 // Make sure at least one encoding is enabled. |
| 91 ASSERT_TRUE(encoding_is_enabled); | 91 ASSERT_TRUE(encoding_is_enabled); |
| 92 } | 92 } |
| OLD | NEW |