Chromium Code Reviews| 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 { | |
|
please use gerrit instead
2015/06/06 01:42:12
Put MultilingualSpellcheckServiceBrowserTest right
Julius
2015/06/12 20:10:15
Done.
| |
| 51 public: | |
| 52 Profile* GetProfile() { return browser()->profile(); } | |
| 53 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 54 command_line->AppendSwitch(switches::kEnableMultilingualSpellChecker); | |
| 55 } | |
| 56 }; | |
| 57 | |
| 44 // Tests that we can delete a corrupted BDICT file used by hunspell. We do not | 58 // 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. | 59 // run this test on Mac because Mac does not use hunspell by default. |
| 46 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, DeleteCorruptedBDICT) { | 60 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, DeleteCorruptedBDICT) { |
| 47 // Write the corrupted BDICT data to create a corrupted BDICT file. | 61 // Write the corrupted BDICT data to create a corrupted BDICT file. |
| 48 base::FilePath dict_dir; | 62 base::FilePath dict_dir; |
| 49 ASSERT_TRUE(PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir)); | 63 ASSERT_TRUE(PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir)); |
| 50 base::FilePath bdict_path = | 64 base::FilePath bdict_path = |
| 51 chrome::spellcheck_common::GetVersionedFileName("en-US", dict_dir); | 65 chrome::spellcheck_common::GetVersionedFileName("en-US", dict_dir); |
| 52 | 66 |
| 53 size_t actual = base::WriteFile(bdict_path, | 67 size_t actual = base::WriteFile(bdict_path, |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 82 // leaking it when this test fails. | 96 // leaking it when this test fails. |
| 83 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); | 97 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); |
| 84 content::RunAllPendingInMessageLoop(content::BrowserThread::UI); | 98 content::RunAllPendingInMessageLoop(content::BrowserThread::UI); |
| 85 EXPECT_EQ(SpellcheckService::BDICT_CORRUPTED, | 99 EXPECT_EQ(SpellcheckService::BDICT_CORRUPTED, |
| 86 SpellcheckService::GetStatusEvent()); | 100 SpellcheckService::GetStatusEvent()); |
| 87 if (base::PathExists(bdict_path)) { | 101 if (base::PathExists(bdict_path)) { |
| 88 ADD_FAILURE(); | 102 ADD_FAILURE(); |
| 89 EXPECT_TRUE(base::DeleteFile(bdict_path, true)); | 103 EXPECT_TRUE(base::DeleteFile(bdict_path, true)); |
| 90 } | 104 } |
| 91 } | 105 } |
| 106 | |
| 107 IN_PROC_BROWSER_TEST_F(MultilingualSpellcheckServiceBrowserTest, | |
| 108 GetSpellCheckLanguages) { | |
| 109 BrowserContext* context = static_cast<BrowserContext*>(GetProfile()); | |
| 110 PrefService* prefs = user_prefs::UserPrefs::Get(context); | |
| 111 prefs->SetString(prefs::kSpellCheckDictionaries, "fr,en-US"); | |
|
please use gerrit instead
2015/06/06 01:42:13
Also set kSpellCheckDictionary to something invali
Julius
2015/06/12 20:10:15
It shouldn't be invalid. I'll add a JS test to cli
| |
| 112 prefs->SetString(prefs::kAcceptLanguages, "fr,en-US,en-AU"); | |
|
please use gerrit instead
2015/06/06 01:42:12
Mix up the order of the languages to differ from |
Julius
2015/06/12 20:10:15
Done.
| |
| 113 | |
| 114 std::vector<std::string> languages; | |
| 115 int ret = SpellcheckService::GetSpellCheckLanguages(context, &languages); | |
|
please use gerrit instead
2015/06/06 01:42:13
size_t
Julius
2015/06/12 20:10:15
Done.
| |
| 116 | |
| 117 ASSERT_EQ(ret, 2); | |
|
please use gerrit instead
2015/06/06 01:42:13
EXPECT_EQ(2UL, ret);
EXPECT because this will let
Julius
2015/06/12 20:10:15
Done.
| |
| 118 ASSERT_EQ("fr", languages[0]); | |
| 119 ASSERT_EQ("en-US", languages[1]); | |
| 120 ASSERT_EQ("en-AU", languages[2]); | |
|
please use gerrit instead
2015/06/06 01:42:13
ASSERT_EQ(3UL, languages.size());
EXPECT_EQ("fr",
Julius
2015/06/12 20:10:15
Done.
| |
| 121 } | |
| 122 | |
| 123 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, GetSpellCheckLanguages) { | |
|
please use gerrit instead
2015/06/06 01:42:13
Put IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowse
Julius
2015/06/12 20:10:15
Done.
| |
| 124 BrowserContext* context = static_cast<BrowserContext*>(GetProfile()); | |
| 125 PrefService* prefs = user_prefs::UserPrefs::Get(context); | |
| 126 prefs->SetString(prefs::kSpellCheckDictionary, "fr"); | |
|
please use gerrit instead
2015/06/06 01:42:12
Also set kSpellCheckDictionaries to something inva
Julius
2015/06/12 20:10:14
It shouldn't be invalid. I'll add a JS test to cli
| |
| 127 prefs->SetString(prefs::kAcceptLanguages, "fr,en-US,en-AU"); | |
| 128 | |
| 129 std::vector<std::string> languages; | |
| 130 int ret = SpellcheckService::GetSpellCheckLanguages(context, &languages); | |
|
please use gerrit instead
2015/06/06 01:42:12
size_t
Julius
2015/06/12 20:10:15
Done.
| |
| 131 | |
| 132 ASSERT_EQ(ret, 1); | |
|
please use gerrit instead
2015/06/06 01:42:12
EXPECT_EQ(1UL, ret);
Julius
2015/06/12 20:10:15
Done.
| |
| 133 ASSERT_EQ("fr", languages[0]); | |
|
please use gerrit instead
2015/06/06 01:42:12
ASSERT_EQ(1UL, languages.size());
EXPECT_EQ("fr",
Julius
2015/06/12 20:10:15
Done.
| |
| 134 } | |
| OLD | NEW |