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

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

Issue 2835233002: Fix integration tests in src/chrome and src/extensions so that we can turn on IO thread checks wi... (Closed)
Patch Set: ready for review Created 3 years, 8 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" 5 #include "chrome/browser/spellchecker/spellcheck_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <string> 9 #include <string>
10 #include <tuple> 10 #include <tuple>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/strings/string_piece.h" 17 #include "base/strings/string_piece.h"
18 #include "base/strings/string_split.h" 18 #include "base/strings/string_split.h"
19 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
20 #include "base/synchronization/waitable_event.h" 20 #include "base/synchronization/waitable_event.h"
21 #include "base/threading/thread_restrictions.h"
21 #include "base/values.h" 22 #include "base/values.h"
22 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/spellchecker/spellcheck_factory.h" 24 #include "chrome/browser/spellchecker/spellcheck_factory.h"
24 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
25 #include "chrome/common/chrome_paths.h" 26 #include "chrome/common/chrome_paths.h"
26 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
27 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
28 #include "chrome/test/base/in_process_browser_test.h" 29 #include "chrome/test/base/in_process_browser_test.h"
29 #include "components/prefs/pref_service.h" 30 #include "components/prefs/pref_service.h"
30 #include "components/spellcheck/browser/pref_names.h" 31 #include "components/spellcheck/browser/pref_names.h"
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 263
263 // Tests that we can delete a corrupted BDICT file used by hunspell. We do not 264 // Tests that we can delete a corrupted BDICT file used by hunspell. We do not
264 // run this test on Mac because Mac does not use hunspell by default. 265 // run this test on Mac because Mac does not use hunspell by default.
265 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, DeleteCorruptedBDICT) { 266 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, DeleteCorruptedBDICT) {
266 // Write the corrupted BDICT data to create a corrupted BDICT file. 267 // Write the corrupted BDICT data to create a corrupted BDICT file.
267 base::FilePath dict_dir; 268 base::FilePath dict_dir;
268 ASSERT_TRUE(PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir)); 269 ASSERT_TRUE(PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir));
269 base::FilePath bdict_path = 270 base::FilePath bdict_path =
270 spellcheck::GetVersionedFileName("en-US", dict_dir); 271 spellcheck::GetVersionedFileName("en-US", dict_dir);
271 272
272 size_t actual = base::WriteFile(bdict_path, 273 {
273 reinterpret_cast<const char*>(kCorruptedBDICT), 274 base::ThreadRestrictions::ScopedAllowIO allow_io;
274 arraysize(kCorruptedBDICT)); 275 size_t actual = base::WriteFile(
275 EXPECT_EQ(arraysize(kCorruptedBDICT), actual); 276 bdict_path, reinterpret_cast<const char*>(kCorruptedBDICT),
277 arraysize(kCorruptedBDICT));
278 EXPECT_EQ(arraysize(kCorruptedBDICT), actual);
279 }
276 280
277 // Attach an event to the SpellcheckService object so we can receive its 281 // Attach an event to the SpellcheckService object so we can receive its
278 // status updates. 282 // status updates.
279 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL, 283 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL,
280 base::WaitableEvent::InitialState::NOT_SIGNALED); 284 base::WaitableEvent::InitialState::NOT_SIGNALED);
281 SpellcheckService::AttachStatusEvent(&event); 285 SpellcheckService::AttachStatusEvent(&event);
282 286
283 BrowserContext* context = GetContext(); 287 BrowserContext* context = GetContext();
284 288
285 // Ensure that the SpellcheckService object does not already exist. Otherwise 289 // Ensure that the SpellcheckService object does not already exist. Otherwise
(...skipping 11 matching lines...) Expand all
297 // The SpellCheckHost object will send a BDICT_CORRUPTED event. 301 // The SpellCheckHost object will send a BDICT_CORRUPTED event.
298 SpellcheckServiceFactory::GetForContext(context); 302 SpellcheckServiceFactory::GetForContext(context);
299 303
300 // Check the received event. Also we check if Chrome has successfully deleted 304 // Check the received event. Also we check if Chrome has successfully deleted
301 // the corrupted dictionary. We delete the corrupted dictionary to avoid 305 // the corrupted dictionary. We delete the corrupted dictionary to avoid
302 // leaking it when this test fails. 306 // leaking it when this test fails.
303 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); 307 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE);
304 content::RunAllPendingInMessageLoop(content::BrowserThread::UI); 308 content::RunAllPendingInMessageLoop(content::BrowserThread::UI);
305 EXPECT_EQ(SpellcheckService::BDICT_CORRUPTED, 309 EXPECT_EQ(SpellcheckService::BDICT_CORRUPTED,
306 SpellcheckService::GetStatusEvent()); 310 SpellcheckService::GetStatusEvent());
311 base::ThreadRestrictions::ScopedAllowIO allow_io;
307 if (base::PathExists(bdict_path)) { 312 if (base::PathExists(bdict_path)) {
308 ADD_FAILURE(); 313 ADD_FAILURE();
309 EXPECT_TRUE(base::DeleteFile(bdict_path, true)); 314 EXPECT_TRUE(base::DeleteFile(bdict_path, true));
310 } 315 }
311 } 316 }
312 317
313 // Checks that preferences migrate correctly. 318 // Checks that preferences migrate correctly.
314 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, PreferencesMigrated) { 319 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, PreferencesMigrated) {
315 GetPrefs()->Set(spellcheck::prefs::kSpellCheckDictionaries, 320 GetPrefs()->Set(spellcheck::prefs::kSpellCheckDictionaries,
316 base::ListValue()); 321 base::ListValue());
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 std::string pref; 393 std::string pref;
389 ASSERT_TRUE(GetPrefs() 394 ASSERT_TRUE(GetPrefs()
390 ->GetList(spellcheck::prefs::kSpellCheckDictionaries) 395 ->GetList(spellcheck::prefs::kSpellCheckDictionaries)
391 ->GetString(0, &pref)); 396 ->GetString(0, &pref));
392 EXPECT_EQ("en-US", pref); 397 EXPECT_EQ("en-US", pref);
393 ASSERT_TRUE(GetPrefs() 398 ASSERT_TRUE(GetPrefs()
394 ->GetList(spellcheck::prefs::kSpellCheckDictionaries) 399 ->GetList(spellcheck::prefs::kSpellCheckDictionaries)
395 ->GetString(1, &pref)); 400 ->GetString(1, &pref));
396 EXPECT_EQ("fr", pref); 401 EXPECT_EQ("fr", pref);
397 } 402 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/session_restore_browsertest.cc ('k') | chrome/browser/ssl/ssl_browser_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698