OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "base/command_line.h" |
5 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/prefs/pref_member.h" |
| 8 #include "base/prefs/pref_service.h" |
6 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
7 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/spellchecker/spellcheck_factory.h" | 11 #include "chrome/browser/spellchecker/spellcheck_factory.h" |
9 #include "chrome/browser/spellchecker/spellcheck_service.h" | 12 #include "chrome/browser/spellchecker/spellcheck_service.h" |
10 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
| 15 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/pref_names.h" |
12 #include "chrome/common/spellcheck_common.h" | 17 #include "chrome/common/spellcheck_common.h" |
13 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
| 19 #include "components/user_prefs/user_prefs.h" |
14 #include "content/public/test/test_utils.h" | 20 #include "content/public/test/test_utils.h" |
15 #include "url/gurl.h" | 21 #include "url/gurl.h" |
16 | 22 |
17 using content::BrowserContext; | 23 using content::BrowserContext; |
18 | 24 |
19 namespace { | 25 namespace { |
20 | 26 |
21 // A corrupted BDICT data used in DeleteCorruptedBDICT. Please do not use this | 27 // A corrupted BDICT data used in DeleteCorruptedBDICT. Please do not use this |
22 // BDICT data for other tests. | 28 // BDICT data for other tests. |
23 const uint8 kCorruptedBDICT[] = { | 29 const uint8 kCorruptedBDICT[] = { |
(...skipping 10 matching lines...) Expand all Loading... |
34 | 40 |
35 } // namespace | 41 } // namespace |
36 | 42 |
37 class SpellcheckServiceBrowserTest : public InProcessBrowserTest { | 43 class SpellcheckServiceBrowserTest : public InProcessBrowserTest { |
38 public: | 44 public: |
39 Profile* GetProfile() { | 45 Profile* GetProfile() { |
40 return browser()->profile(); | 46 return browser()->profile(); |
41 } | 47 } |
42 }; | 48 }; |
43 | 49 |
| 50 class MultilingualSpellcheckServiceBrowserTest : public InProcessBrowserTest { |
| 51 public: |
| 52 Profile* GetProfile() { |
| 53 return browser()->profile(); |
| 54 } |
| 55 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 56 command_line->AppendSwitch(switches::kEnableMultilingualSpellChecker); |
| 57 } |
| 58 }; |
| 59 |
44 // Tests that we can delete a corrupted BDICT file used by hunspell. We do not | 60 // Tests that we can delete a corrupted BDICT file used by hunspell. We do not |
45 // run this test on Mac because Mac does not use hunspell by default. | 61 // run this test on Mac because Mac does not use hunspell by default. |
46 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, DeleteCorruptedBDICT) { | 62 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, DeleteCorruptedBDICT) { |
47 // Write the corrupted BDICT data to create a corrupted BDICT file. | 63 // Write the corrupted BDICT data to create a corrupted BDICT file. |
48 base::FilePath dict_dir; | 64 base::FilePath dict_dir; |
49 ASSERT_TRUE(PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir)); | 65 ASSERT_TRUE(PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir)); |
50 base::FilePath bdict_path = | 66 base::FilePath bdict_path = |
51 chrome::spellcheck_common::GetVersionedFileName("en-US", dict_dir); | 67 chrome::spellcheck_common::GetVersionedFileName("en-US", dict_dir); |
52 | 68 |
53 size_t actual = base::WriteFile(bdict_path, | 69 size_t actual = base::WriteFile(bdict_path, |
(...skipping 28 matching lines...) Expand all Loading... |
82 // leaking it when this test fails. | 98 // leaking it when this test fails. |
83 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); | 99 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); |
84 content::RunAllPendingInMessageLoop(content::BrowserThread::UI); | 100 content::RunAllPendingInMessageLoop(content::BrowserThread::UI); |
85 EXPECT_EQ(SpellcheckService::BDICT_CORRUPTED, | 101 EXPECT_EQ(SpellcheckService::BDICT_CORRUPTED, |
86 SpellcheckService::GetStatusEvent()); | 102 SpellcheckService::GetStatusEvent()); |
87 if (base::PathExists(bdict_path)) { | 103 if (base::PathExists(bdict_path)) { |
88 ADD_FAILURE(); | 104 ADD_FAILURE(); |
89 EXPECT_TRUE(base::DeleteFile(bdict_path, true)); | 105 EXPECT_TRUE(base::DeleteFile(bdict_path, true)); |
90 } | 106 } |
91 } | 107 } |
| 108 |
| 109 IN_PROC_BROWSER_TEST_F(MultilingualSpellcheckServiceBrowserTest, |
| 110 GetSpellCheckLanguages) { |
| 111 BrowserContext* context = static_cast<BrowserContext*>(GetProfile()); |
| 112 PrefService* prefs = user_prefs::UserPrefs::Get(context); |
| 113 prefs->SetString(prefs::kSpellCheckDictionaries, "fr,en-US"); |
| 114 prefs->SetString(prefs::kAcceptLanguages, "fr,en-US,en-AU"); |
| 115 |
| 116 std::vector<std::string> languages; |
| 117 int ret = SpellcheckService::GetSpellCheckLanguages(context, &languages); |
| 118 |
| 119 ASSERT_EQ(ret, 2); |
| 120 ASSERT_EQ("fr", languages[0]); |
| 121 ASSERT_EQ("en-US", languages[1]); |
| 122 ASSERT_EQ("en-AU", languages[2]); |
| 123 } |
| 124 |
| 125 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, GetSpellCheckLanguages) { |
| 126 BrowserContext* context = static_cast<BrowserContext*>(GetProfile()); |
| 127 PrefService* prefs = user_prefs::UserPrefs::Get(context); |
| 128 prefs->SetString(prefs::kSpellCheckDictionary, "fr"); |
| 129 prefs->SetString(prefs::kAcceptLanguages, "fr,en-US,en-AU"); |
| 130 |
| 131 std::vector<std::string> languages; |
| 132 int ret = SpellcheckService::GetSpellCheckLanguages(context, &languages); |
| 133 |
| 134 ASSERT_EQ(ret, 1); |
| 135 ASSERT_EQ("fr", languages[0]); |
| 136 } |
OLD | NEW |