Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: chrome/browser/spellchecker/spellcheck_service_browsertest.cc

Issue 1156473007: Enables the user to select multiple languages for spellchecking (UI) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved spellcheck_service_browsertest to a unittest, cleaned code, replied to comments, stopped Mac … Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/spellchecker/spellcheck_service.h"
6
5 #include "base/path_service.h" 7 #include "base/path_service.h"
6 #include "base/synchronization/waitable_event.h" 8 #include "base/synchronization/waitable_event.h"
7 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/spellchecker/spellcheck_factory.h" 10 #include "chrome/browser/spellchecker/spellcheck_factory.h"
9 #include "chrome/browser/spellchecker/spellcheck_service.h" 11 #include "chrome/browser/spellchecker/spellcheck_service.h"
10 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
11 #include "chrome/common/chrome_paths.h" 13 #include "chrome/common/chrome_paths.h"
12 #include "chrome/common/spellcheck_common.h" 14 #include "chrome/common/spellcheck_common.h"
13 #include "chrome/test/base/in_process_browser_test.h" 15 #include "chrome/test/base/in_process_browser_test.h"
14 #include "content/public/test/test_utils.h" 16 #include "content/public/test/test_utils.h"
15 #include "url/gurl.h"
16 17
17 using content::BrowserContext; 18 using content::BrowserContext;
18 19
19 namespace { 20 namespace {
20 21
21 // A corrupted BDICT data used in DeleteCorruptedBDICT. Please do not use this 22 // A corrupted BDICT data used in DeleteCorruptedBDICT. Please do not use this
22 // BDICT data for other tests. 23 // BDICT data for other tests.
23 const uint8 kCorruptedBDICT[] = { 24 const uint8 kCorruptedBDICT[] = {
24 0x42, 0x44, 0x69, 0x63, 0x02, 0x00, 0x01, 0x00, 25 0x42, 0x44, 0x69, 0x63, 0x02, 0x00, 0x01, 0x00,
25 0x20, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x00, 0x00, 26 0x20, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x00, 0x00,
26 0x65, 0x72, 0xe0, 0xac, 0x27, 0xc7, 0xda, 0x66, 27 0x65, 0x72, 0xe0, 0xac, 0x27, 0xc7, 0xda, 0x66,
27 0x6d, 0x1e, 0xa6, 0x35, 0xd1, 0xf6, 0xb7, 0x35, 28 0x6d, 0x1e, 0xa6, 0x35, 0xd1, 0xf6, 0xb7, 0x35,
28 0x32, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 29 0x32, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00,
29 0x39, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, 30 0x39, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00,
30 0x0a, 0x0a, 0x41, 0x46, 0x20, 0x30, 0x00, 0x00, 31 0x0a, 0x0a, 0x41, 0x46, 0x20, 0x30, 0x00, 0x00,
31 0x00, 0x00, 0x00, 0xe6, 0x49, 0x00, 0x68, 0x02, 32 0x00, 0x00, 0x00, 0xe6, 0x49, 0x00, 0x68, 0x02,
32 0x73, 0x06, 0x74, 0x0b, 0x77, 0x11, 0x79, 0x15, 33 0x73, 0x06, 0x74, 0x0b, 0x77, 0x11, 0x79, 0x15,
33 }; 34 };
34 35
35 } // namespace 36 } // namespace
36 37
37 class SpellcheckServiceBrowserTest : public InProcessBrowserTest { 38 class SpellcheckServiceBrowserTest : public InProcessBrowserTest{
38 public: 39 public:
39 Profile* GetProfile() { 40 SpellcheckServiceBrowserTest() {}
40 return browser()->profile(); 41 ~SpellcheckServiceBrowserTest() override {}
42
43 BrowserContext* GetContext() {
44 return static_cast<BrowserContext*>(browser()->profile());
41 } 45 }
46
47 private:
48 DISALLOW_COPY_AND_ASSIGN(SpellcheckServiceBrowserTest);
42 }; 49 };
43 50
44 // Tests that we can delete a corrupted BDICT file used by hunspell. We do not 51 // 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. 52 // run this test on Mac because Mac does not use hunspell by default.
46 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, DeleteCorruptedBDICT) { 53 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, DeleteCorruptedBDICT) {
47 // Write the corrupted BDICT data to create a corrupted BDICT file. 54 // Write the corrupted BDICT data to create a corrupted BDICT file.
48 base::FilePath dict_dir; 55 base::FilePath dict_dir;
49 ASSERT_TRUE(PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir)); 56 ASSERT_TRUE(PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir));
50 base::FilePath bdict_path = 57 base::FilePath bdict_path =
51 chrome::spellcheck_common::GetVersionedFileName("en-US", dict_dir); 58 chrome::spellcheck_common::GetVersionedFileName("en-US", dict_dir);
52 59
53 size_t actual = base::WriteFile(bdict_path, 60 size_t actual = base::WriteFile(
54 reinterpret_cast<const char*>(kCorruptedBDICT), 61 bdict_path, reinterpret_cast<const char*>(kCorruptedBDICT),
55 arraysize(kCorruptedBDICT)); 62 arraysize(kCorruptedBDICT));
56 EXPECT_EQ(arraysize(kCorruptedBDICT), actual); 63 EXPECT_EQ(arraysize(kCorruptedBDICT), actual);
57 64
58 // Attach an event to the SpellcheckService object so we can receive its 65 // Attach an event to the SpellcheckService object so we can receive its
59 // status updates. 66 // status updates.
60 base::WaitableEvent event(true, false); 67 base::WaitableEvent event(true, false);
61 SpellcheckService::AttachStatusEvent(&event); 68 SpellcheckService::AttachStatusEvent(&event);
62 69
63 BrowserContext * context = static_cast<BrowserContext*>(GetProfile()); 70 BrowserContext* context = GetContext();
64 71
65 // Ensure that the SpellcheckService object does not already exist. Otherwise 72 // Ensure that the SpellcheckService object does not already exist. Otherwise
66 // the next line will not force creation of the SpellcheckService and the 73 // the next line will not force creation of the SpellcheckService and the
67 // test will fail. 74 // test will fail.
68 SpellcheckService* service = static_cast<SpellcheckService*>( 75 SpellcheckService* service = static_cast<SpellcheckService*>(
69 SpellcheckServiceFactory::GetInstance()->GetServiceForBrowserContext( 76 SpellcheckServiceFactory::GetInstance()->GetServiceForBrowserContext(
70 context, 77 context, false));
71 false));
72 ASSERT_EQ(NULL, service); 78 ASSERT_EQ(NULL, service);
73 79
74 // Getting the spellcheck_service will initialize the SpellcheckService 80 // Getting the spellcheck_service will initialize the SpellcheckService
75 // object with the corrupted BDICT file created above since the hunspell 81 // object with the corrupted BDICT file created above since the hunspell
76 // dictionary is loaded in the SpellcheckService constructor right now. 82 // dictionary is loaded in the SpellcheckService constructor right now.
77 // The SpellCheckHost object will send a BDICT_CORRUPTED event. 83 // The SpellCheckHost object will send a BDICT_CORRUPTED event.
78 SpellcheckServiceFactory::GetForContext(context); 84 SpellcheckServiceFactory::GetForContext(context);
79 85
80 // Check the received event. Also we check if Chrome has successfully deleted 86 // Check the received event. Also we check if Chrome has successfully deleted
81 // the corrupted dictionary. We delete the corrupted dictionary to avoid 87 // the corrupted dictionary. We delete the corrupted dictionary to avoid
82 // leaking it when this test fails. 88 // leaking it when this test fails.
83 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); 89 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE);
84 content::RunAllPendingInMessageLoop(content::BrowserThread::UI); 90 content::RunAllPendingInMessageLoop(content::BrowserThread::UI);
85 EXPECT_EQ(SpellcheckService::BDICT_CORRUPTED, 91 EXPECT_EQ(SpellcheckService::BDICT_CORRUPTED,
86 SpellcheckService::GetStatusEvent()); 92 SpellcheckService::GetStatusEvent());
87 if (base::PathExists(bdict_path)) { 93 if (base::PathExists(bdict_path)) {
88 ADD_FAILURE(); 94 ADD_FAILURE();
89 EXPECT_TRUE(base::DeleteFile(bdict_path, true)); 95 EXPECT_TRUE(base::DeleteFile(bdict_path, true));
90 } 96 }
91 } 97 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698