1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/path_service.h"
6 #include "base/synchronization/waitable_event.h"
7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/spellchecker/spellcheck_host.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/common/chrome_paths.h"
11 #include "chrome/common/spellcheck_common.h"
12 #include "chrome/test/base/in_process_browser_test.h"
13 #include "chrome/test/base/ui_test_utils.h"
14 #include "content/browser/tab_contents/tab_contents.h"
15 #include "googleurl/src/gurl.h"
19 // A corrupted BDICT data used in DeleteCorruptedBDICT. Please do not use this
20 // BDICT data for other tests.
21 const uint8 kCorruptedBDICT
[] = {
22 0x42, 0x44, 0x69, 0x63, 0x02, 0x00, 0x01, 0x00,
23 0x20, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x00, 0x00,
24 0x65, 0x72, 0xe0, 0xac, 0x27, 0xc7, 0xda, 0x66,
25 0x6d, 0x1e, 0xa6, 0x35, 0xd1, 0xf6, 0xb7, 0x35,
26 0x32, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00,
27 0x39, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00,
28 0x0a, 0x0a, 0x41, 0x46, 0x20, 0x30, 0x00, 0x00,
29 0x00, 0x00, 0x00, 0xe6, 0x49, 0x00, 0x68, 0x02,
30 0x73, 0x06, 0x74, 0x0b, 0x77, 0x11, 0x79, 0x15,
35 class SpellCheckHostBrowserTest
: public InProcessBrowserTest
{
38 // Tests that we can delete a corrupted BDICT file used by hunspell. We do not
39 // run this test on Mac because Mac does not use hunspell by default.
40 IN_PROC_BROWSER_TEST_F(SpellCheckHostBrowserTest
, DeleteCorruptedBDICT
) {
41 // Write the corrupted BDICT data to create a corrupted BDICT file.
43 ASSERT_TRUE(PathService::Get(chrome::DIR_APP_DICTIONARIES
, &dict_dir
));
45 SpellCheckCommon::GetVersionedFileName("en-US", dict_dir
);
47 size_t actual
= file_util::WriteFile(bdict_path
,
48 reinterpret_cast<const char*>(kCorruptedBDICT
),
49 arraysize(kCorruptedBDICT
));
50 EXPECT_EQ(arraysize(kCorruptedBDICT
), actual
);
52 // Attach an event to the SpellCheckHost object so we can receive its status
54 base::WaitableEvent
event(true, false);
55 SpellCheckHost::AttachStatusEvent(&event
);
57 // Initialize the SpellCheckHost object with the corrupted BDICT file created
58 // above. The SpellCheckHost object will send a BDICT_CORRUPTED event.
59 browser()->profile()->ReinitializeSpellCheckHost(false);
61 // Check the received event. Also we check if Chrome has successfully deleted
62 // the corrupted dictionary. We delete the corrupted dictionary to avoid
63 // leaking it when this test fails.
64 int type
= SpellCheckHost::WaitStatusEvent();
65 EXPECT_EQ(SpellCheckHost::BDICT_CORRUPTED
, type
);
66 if (file_util::PathExists(bdict_path
)) {
68 EXPECT_TRUE(file_util::Delete(bdict_path
, true));