| 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/path_service.h" | 5 #include "base/path_service.h" |
| 6 #include "base/synchronization/waitable_event.h" | 6 #include "base/synchronization/waitable_event.h" |
| 7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/spellchecker/spellcheck_factory.h" | 8 #include "chrome/browser/spellchecker/spellcheck_factory.h" |
| 9 #include "chrome/browser/spellchecker/spellcheck_service.h" | 9 #include "chrome/browser/spellchecker/spellcheck_service.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/common/chrome_paths.h" | 11 #include "chrome/common/chrome_paths.h" |
| 12 #include "chrome/common/spellcheck_common.h" | 12 #include "chrome/common/spellcheck_common.h" |
| 13 #include "chrome/test/base/in_process_browser_test.h" | 13 #include "chrome/test/base/in_process_browser_test.h" |
| 14 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
| 15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 16 | 16 |
| 17 using content::BrowserContext; |
| 18 |
| 17 namespace { | 19 namespace { |
| 18 | 20 |
| 19 // A corrupted BDICT data used in DeleteCorruptedBDICT. Please do not use this | 21 // A corrupted BDICT data used in DeleteCorruptedBDICT. Please do not use this |
| 20 // BDICT data for other tests. | 22 // BDICT data for other tests. |
| 21 const uint8 kCorruptedBDICT[] = { | 23 const uint8 kCorruptedBDICT[] = { |
| 22 0x42, 0x44, 0x69, 0x63, 0x02, 0x00, 0x01, 0x00, | 24 0x42, 0x44, 0x69, 0x63, 0x02, 0x00, 0x01, 0x00, |
| 23 0x20, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x00, 0x00, | 25 0x20, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x00, 0x00, |
| 24 0x65, 0x72, 0xe0, 0xac, 0x27, 0xc7, 0xda, 0x66, | 26 0x65, 0x72, 0xe0, 0xac, 0x27, 0xc7, 0xda, 0x66, |
| 25 0x6d, 0x1e, 0xa6, 0x35, 0xd1, 0xf6, 0xb7, 0x35, | 27 0x6d, 0x1e, 0xa6, 0x35, 0xd1, 0xf6, 0xb7, 0x35, |
| 26 0x32, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, | 28 0x32, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 51 size_t actual = file_util::WriteFile(bdict_path, | 53 size_t actual = file_util::WriteFile(bdict_path, |
| 52 reinterpret_cast<const char*>(kCorruptedBDICT), | 54 reinterpret_cast<const char*>(kCorruptedBDICT), |
| 53 arraysize(kCorruptedBDICT)); | 55 arraysize(kCorruptedBDICT)); |
| 54 EXPECT_EQ(arraysize(kCorruptedBDICT), actual); | 56 EXPECT_EQ(arraysize(kCorruptedBDICT), actual); |
| 55 | 57 |
| 56 // Attach an event to the SpellcheckService object so we can receive its | 58 // Attach an event to the SpellcheckService object so we can receive its |
| 57 // status updates. | 59 // status updates. |
| 58 base::WaitableEvent event(true, false); | 60 base::WaitableEvent event(true, false); |
| 59 SpellcheckService::AttachStatusEvent(&event); | 61 SpellcheckService::AttachStatusEvent(&event); |
| 60 | 62 |
| 63 BrowserContext * context = static_cast<BrowserContext*>(GetProfile()); |
| 64 |
| 61 // Ensure that the SpellcheckService object does not already exist. Otherwise | 65 // Ensure that the SpellcheckService object does not already exist. Otherwise |
| 62 // the next line will not force creation of the SpellcheckService and the | 66 // the next line will not force creation of the SpellcheckService and the |
| 63 // test will fail. | 67 // test will fail. |
| 64 SpellcheckService* service = | 68 SpellcheckService* service = static_cast<SpellcheckService*>( |
| 65 SpellcheckServiceFactory::GetForProfileWithoutCreating(GetProfile()); | 69 SpellcheckServiceFactory::GetInstance()->GetServiceForBrowserContext( |
| 70 context, |
| 71 false)); |
| 66 ASSERT_EQ(NULL, service); | 72 ASSERT_EQ(NULL, service); |
| 67 | 73 |
| 68 // Getting the spellcheck_service will initialize the SpellcheckService | 74 // Getting the spellcheck_service will initialize the SpellcheckService |
| 69 // object with the corrupted BDICT file created above since the hunspell | 75 // object with the corrupted BDICT file created above since the hunspell |
| 70 // dictionary is loaded in the SpellcheckService constructor right now. | 76 // dictionary is loaded in the SpellcheckService constructor right now. |
| 71 // The SpellCheckHost object will send a BDICT_CORRUPTED event. | 77 // The SpellCheckHost object will send a BDICT_CORRUPTED event. |
| 72 SpellcheckServiceFactory::GetForProfile(GetProfile()); | 78 SpellcheckServiceFactory::GetForContext(context); |
| 73 | 79 |
| 74 // Check the received event. Also we check if Chrome has successfully deleted | 80 // Check the received event. Also we check if Chrome has successfully deleted |
| 75 // the corrupted dictionary. We delete the corrupted dictionary to avoid | 81 // the corrupted dictionary. We delete the corrupted dictionary to avoid |
| 76 // leaking it when this test fails. | 82 // leaking it when this test fails. |
| 77 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); | 83 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); |
| 78 content::RunAllPendingInMessageLoop(content::BrowserThread::UI); | 84 content::RunAllPendingInMessageLoop(content::BrowserThread::UI); |
| 79 EXPECT_EQ(SpellcheckService::BDICT_CORRUPTED, | 85 EXPECT_EQ(SpellcheckService::BDICT_CORRUPTED, |
| 80 SpellcheckService::GetStatusEvent()); | 86 SpellcheckService::GetStatusEvent()); |
| 81 if (base::PathExists(bdict_path)) { | 87 if (base::PathExists(bdict_path)) { |
| 82 ADD_FAILURE(); | 88 ADD_FAILURE(); |
| 83 EXPECT_TRUE(base::DeleteFile(bdict_path, true)); | 89 EXPECT_TRUE(base::DeleteFile(bdict_path, true)); |
| 84 } | 90 } |
| 85 } | 91 } |
| OLD | NEW |