Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove "Ask Brave for suggestions" from context menu spellcheck section #682

Merged
merged 1 commit into from
Oct 30, 2018

Conversation

mkarolin
Copy link
Collaborator

@mkarolin mkarolin commented Oct 18, 2018

Hides RenderViewContextMenu::AddSpellCheckServiceItem method with one in BraveRenderViewContextMenu that does not add Ask Brave menu item.

Fixes brave/brave-browser#1623

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Verified that these changes build without errors on
    • Windows
    • macOS
    • Linux
  • Verified that these changes pass automated tests (npm test brave_unit_tests && npm test brave_browser_tests) on
    • Windows
    • macOS
    • Linux
  • Ran git rebase master (if needed).
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.
  • Request a security/privacy review as needed.
  • Add appropriate QA labels (QA/Yes or QA/No) to include the closed issue in milestone

Automated Test Plan:

On all platforms:
npm run test -- brave_browser_tests --filter=BraveSpellingMenuObserverTest.*

On Windows and Linux:
npm run test -- brave_browser_tests --filter=BraveSpellingOptionsSubMenuObserverTest.*

Test Plan:

  1. [Windows & Linux] Verify that Spellcheck sub-menu doesn't contain "Ask Brave for suggestions":
  • Start the browser and open brave://settings/languages,
  • Expand "Spell check" section and make sure that at least one language is turned on for spell checking,
  • In a new tab navigate to google.com,
  • Right-click in the search box on the site and expand Spellcheck sub-menu,
  • Verify that the sub-menu doesn't contain a menu item "Ask Brave for suggestions".
  1. [Windows & Linux] Verify that Spellcheck sub-menu doesn't end with a separator when spell checking is turned off for all languages:
  • Start the browser and open brave://settings/languages,
  • Expand "Spell check" section and turn off spell checking for all languages,
  • In a new tab navigate to google.com,
  • Right-click in the search box on the site and expand Spellcheck sub-menu,
  • Verify that the sub-menu doesn't end with a separator.
  1. [All Platforms] Verify that spelling suggestions don't show "Ask Brave for suggestions":
  • Start the browser and open brave://settings/languages,
  • Expand "Spell check" section and make sure that at least one language is turned on for spell checking,
  • In a new tab navigate to dictionary.com,
  • Right-click in the search box on the site and expand Spellcheck sub-menu, make sure that "Check for spelling of text fields" menu item is checked,
  • Type a misspelled word into the search box on the site (e.g. correctz),
  • Right click on the misspelled word,
  • Verify that "Ask Brave for suggestions" doesn't show in the menu (after "Add to dictionary").

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

@mkarolin mkarolin self-assigned this Oct 18, 2018
@bsclifton
Copy link
Member

@mkarolin would it be possible to make a browser test for this? I'm not 100% sure context menu items can be tested, but it would be cool to check 😄. If it was possible, a great test would be to ensure this item never shows up when right clicking a text field

@mkarolin
Copy link
Collaborator Author

mkarolin commented Oct 18, 2018 via email

@bsclifton
Copy link
Member

Change worked as expected- however, it leaves an awkward separator above where the item used to be:
screen shot 2018-10-18 at 2 20 40 pm

It might be better to look at the caller for this, which seems to be:
src/chrome/browser/renderer_context_menu/spelling_menu_observer.cc
(see InitMenu())

While we're there, you might check other places that use integrate_spelling_service_ member variable (which I think is tied to the Profile preference spellcheck.use_spelling_service, which is set to false by default)

@mkarolin
Copy link
Collaborator Author

Oh that's interesting, I always have another item there:

image

I'll take a closer look to see what appears when. Thanks for trying it out!

@mkarolin mkarolin force-pushed the maxk-remove-ask-brave-for-suggestions branch from 1d53a44 to caf6b4f Compare October 22, 2018 16:10
@mkarolin mkarolin changed the title Remove "Ask Brave for suggestions" from context menu spellcheck section WIP: Remove "Ask Brave for suggestions" from context menu spellcheck section Oct 22, 2018
@mkarolin mkarolin force-pushed the maxk-remove-ask-brave-for-suggestions branch from caf6b4f to e4eef6b Compare October 22, 2018 17:34
@mkarolin mkarolin changed the title WIP: Remove "Ask Brave for suggestions" from context menu spellcheck section Remove "Ask Brave for suggestions" from context menu spellcheck section Oct 22, 2018
@mkarolin
Copy link
Collaborator Author

mkarolin commented Oct 22, 2018

Updated. There were 2 places where "Ask Brave for suggestions" could show up:

  1. In the Spellcheck sub-menu,
  2. In the menu if spellcheck is enabled for text fields and the menu is invoked on a misspelled word.

Updated test plan to check for both cases.
Added browser tests to verify these cases and to verify the Spellcheck sub-menu doesn't end with a separator.

DCHECK(submenu_model_.GetItemCount());

// Special accommodations for gtest.
if (gtest_mode_ != GTEST_MODE_DISABLED) {
Copy link
Member

@bsclifton bsclifton Oct 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought for the future (I'm curious too) - you might check if unit/browser tests expose a #define that you can check for with preprocessors? ex: you could wrap this section (and potentially the definition/setting of gtest_mode_) with #ifdef/#endif guards. I'm not sure if there's a best practice? ex: a common way to check. But you could check like this:

#ifdef IN_PROC_BROWSER_TEST_
#endif

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking for something like this as well but didn't see any additional definitions in the tests build in our build setup. gtest itself doesn't seem to add any (https://stackoverflow.com/questions/6077833/how-to-check-if-google-test-is-running-in-my-code). Ideally, I wouldn't want to have a different code path for tests in the first place, but in this case it would mean creating a more complex mock object (the current one was taken from Chromium and slightly modified).

int index = submenu_model_.GetItemCount() - 1;
if (index >= 0 &&
submenu_model_.GetTypeAt(index) == ui::MenuModel::TYPE_SEPARATOR)
submenu_model_.RemoveItemAt(index);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: when a comparison is multiple lines (or has weird spacing, enclosing the block within { and } can make it more readable (clearly capturing the start/end)

Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really well done! 😄👍 I ran through the manual test plans, automated tests, and then reviewed the code. Left a few comments (nitpicks 😛- no action needed; just food for thought). Great job 😄

@bsclifton
Copy link
Member

Basically ready for merge - just going to verify tests work great on macOS, since this option isn't available there (build in progress...)

@bsclifton
Copy link
Member

Getting some compile errors (likely need platform preprocessor guards around this):

../../brave/browser/renderer_context_menu/brave_spelling_options_submenu_observer.cc:52:35: error: use of undeclared identifier 'IDS_CONTENT_CONTEXT_SPELLCHECK_MENU'
        l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU),
                                  ^
../../brave/browser/renderer_context_menu/brave_spelling_options_submenu_observer.cc:62:35: error: use of undeclared identifier 'IDS_CONTENT_CONTEXT_SPELLCHECK_MENU'
        l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU));
                                  ^
2 errors generated.

Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we'll need to put some preprocessors around this functionality. I think we can subclass SpellingOptionsSubMenuObserver wrapped in a #if !defined(OS_MACOSX)

The tests may need that same guard checked too

@mkarolin mkarolin force-pushed the maxk-remove-ask-brave-for-suggestions branch 2 times, most recently from d77639f to 69d1689 Compare October 24, 2018 19:28
@mkarolin
Copy link
Collaborator Author

Updated with ifdefs for Mac. One curious thing: in the original render_view_context_menu.cc code the header inclusion is predicated on #if !BUILDFLAG(USE_BROWSER_SPELLCHECKER) whereas the use of SpellingOptionsSubMenuObserver is controlled by if !defined (OS_MACOSX). I kept it the same in the override.

one in BraveRenderViewContextMenu that does not add Ask Brave menu item.

Fixes brave/brave-browser#1623

Also, overrides SpellingMenuObserver to remove a possible dangling menu
separator. Adds browser tests for spelling menu and spelling options
submenu that check that the "Ask Brave for suggestions" menu item is not
present.
@bsclifton bsclifton force-pushed the maxk-remove-ask-brave-for-suggestions branch from 69d1689 to c82efbc Compare October 29, 2018 23:43
@bsclifton
Copy link
Member

Built great on macOS and all unit/browser tests passed; waiting for Windows to finish...

Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great on Windows (ran through each test plan) and compiles/tests pass/etc on macOS 😄 👍

@bsclifton bsclifton merged commit d743327 into master Oct 30, 2018
@bsclifton bsclifton deleted the maxk-remove-ask-brave-for-suggestions branch October 30, 2018 03:56
bsclifton added a commit that referenced this pull request Oct 30, 2018
Remove "Ask Brave for suggestions" from context menu spellcheck section
bsclifton added a commit that referenced this pull request Oct 30, 2018
Remove "Ask Brave for suggestions" from context menu spellcheck section
@bsclifton
Copy link
Member

master d743327
0.57.x 5d8323a
0.56.x d674e0b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ask Brave for suggestion needs to be removed
3 participants