Commit 45409960 authored by Guillaume Jenkins's avatar Guillaume Jenkins Committed by Commit Bot

[Spellcheck] Fix spell check browser tests

When I attempted  to submit the field trial test for the Windows native
spell checker integration, the try bots picked up several crashes in
existing tests when the native spell checker flags are enabled in
Chrome:
https://cr-buildbucket.appspot.com/build/8891251817173916304

The crashes were caused by the use of raw pointers instead of weak
pointers, because the SpellcheckHunspellDictionary object was deleted
by the time the callback from PlatformSupportsLanguage() was invoked.

Change-Id: I8ac2afa9b66a11a2846a086f23d024ce380f77eb
Bug: 463364,
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2003087Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Guillaume Jenkins <gujen@google.com>
Auto-Submit: Guillaume Jenkins <gujen@google.com>
Cr-Commit-Position: refs/heads/master@{#732910}
parent 1882ec4a
......@@ -145,7 +145,7 @@ void SpellcheckHunspellDictionary::Load() {
language_,
base::BindOnce(
&SpellcheckHunspellDictionary::PlatformSupportsLanguageComplete,
base::Unretained(this)));
weak_ptr_factory_.GetWeakPtr()));
return;
}
#endif // USE_BROWSER_SPELLCHECKER
......@@ -447,7 +447,7 @@ void SpellcheckHunspellDictionary::PlatformSupportsLanguageComplete(
spellcheck_platform::SetLanguage(
language_, base::BindOnce(&SpellcheckHunspellDictionary::
SpellCheckPlatformSetLanguageComplete,
base::Unretained(this)));
weak_ptr_factory_.GetWeakPtr()));
return;
}
#endif // BUILDFLAG(USE_BROWSER_SPELLCHECKER)
......
......@@ -19,6 +19,7 @@
#include "base/test/metrics/histogram_tester.h"
#include "base/threading/thread_restrictions.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/spellchecker/spell_check_host_chrome_impl.h"
#include "chrome/browser/spellchecker/spellcheck_factory.h"
......@@ -40,6 +41,10 @@
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#if BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
#include "components/spellcheck/common/spellcheck_features.h"
#endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
using content::BrowserContext;
using content::RenderProcessHost;
......@@ -445,6 +450,15 @@ IN_PROC_BROWSER_TEST_F(SpellcheckServiceHostBrowserTest, CallSpellingService) {
// Tests that we can delete a corrupted BDICT file used by hunspell. We do not
// run this test on Mac because Mac does not use hunspell by default.
IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, DeleteCorruptedBDICT) {
#if BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
if (spellcheck::UseWinHybridSpellChecker()) {
// If doing hybrid spell checking on Windows, Hunspell dictionaries are not
// used for en-US, so the corrupt dictionary event will never be raised.
// Skip this test.
return;
}
#endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
// Corrupted BDICT data: please do not use this BDICT data for other tests.
const uint8_t kCorruptedBDICT[] = {
0x42, 0x44, 0x69, 0x63, 0x02, 0x00, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00,
......
......@@ -6,6 +6,7 @@
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "components/spellcheck/common/spellcheck_features.h"
#include "components/spellcheck/renderer/spellcheck.h"
#include "testing/gtest/include/gtest/gtest.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment