Skip to content

Commit

Permalink
Adding language method
Browse files Browse the repository at this point in the history
  • Loading branch information
david-dick committed Jan 4, 2024
1 parent f58a113 commit c2c0118
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,13 @@ SUBROUTINES/METHODS
$firefox->key_up(CONTROL())
)->content();

language

accepts an optional value for the Accept-Language
<https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language>
header and sets this using the profile preferences. It returns the
current value, such as 'en-US, en'.

loaded

returns true if document.readyState === "complete"
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,10 @@ accepts a parameter describing a key and returns an action for use in the [perfo
$firefox->key_up(CONTROL())
)->content();

## language

accepts an optional value for the [Accept-Language](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language) header and sets this using the profile preferences. It returns the current value, such as 'en-US, en'.

## loaded

returns true if `document.readyState === "complete"`
Expand Down
21 changes: 21 additions & 0 deletions lib/Firefox/Marionette.pm
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,23 @@ sub BY_PARTIAL {
return 'partial link text';
}

sub language {
my ( $self, $new_language ) = @_;
my $pref_name = 'intl.accept_languages';
my $script =
'return branch.getComplexValue(arguments[0], Components.interfaces.nsIPrefLocalizedString).data';
my $old = $self->_context('chrome');
my $old_language = $self->script(
$self->_compress_script( $self->_prefs_interface_preamble() . $script ),
args => [$pref_name]
);
$self->_context($old);
if ( defined $new_language ) {
$self->set_pref( $pref_name, $new_language );
}
return $old_language;
}

sub _prefs_interface_preamble {
my ($self) = @_;
return <<'_JS_'; # modules/libpref/nsIPrefService.idl
Expand Down Expand Up @@ -13026,6 +13043,10 @@ accepts a parameter describing a key and returns an action for use in the L<perf
$firefox->key_up(CONTROL())
)->content();

=head2 language

accepts an optional value for the L<Accept-Language|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language> header and sets this using the profile preferences. It returns the current value, such as 'en-US, en'.

=head2 loaded

returns true if C<document.readyState === "complete">
Expand Down
13 changes: 13 additions & 0 deletions t/01-marionette.t
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,19 @@ SKIP: {
ok($firefox->aria_role($element) =~ /^(?:toggle[ ])?button$/smx, "Retrieved the ARIA role correctly:" . $firefox->aria_role($element));
ok($firefox->find_id('save')->aria_role() =~ /^(?:toggle[ ])?button$/smx, "Retrieved the ARIA label correctly:" . $firefox->find_id('save')->aria_role());
}
my $browser_language = $firefox->script('return navigator.language');
my $quoted_browser_language = quotemeta $browser_language;
my $original_language = $firefox->language();
ok($original_language =~ /^$quoted_browser_language/smx, "\$firefox->language() contains navigator.language as it's first entry:$original_language vs $browser_language");
my $new_language = 'en-AU,en-GB, en';
ok($firefox->language($new_language) eq $original_language, "\$firefox->language(\"$new_language\") returns correctly");
$browser_language = $firefox->script('return navigator.language');
$quoted_browser_language = quotemeta $browser_language;
ok($new_language =~ /^$quoted_browser_language/smx, "\$firefox->language() contains navigator.language as it's first entry:$new_language vs $browser_language");
my $lone_language = 'en-GB';
ok($firefox->language($lone_language) eq $new_language, "\$firefox->language(\"$lone_language\") returns correctly");
$browser_language = $firefox->script('return navigator.language');
ok($lone_language eq $browser_language, "\$firefox->language() matches navigator.language b/c there is only one entry:$lone_language vs $browser_language");
if ($ENV{FIREFOX_HOST}) {
} elsif (($^O eq 'openbsd') && (Cwd::cwd() !~ /^($quoted_home_directory\/Downloads|\/tmp)/)) {
diag("Skipping checks that use a file:// url b/c of OpenBSD's unveil functionality - see https://bugzilla.mozilla.org/show_bug.cgi?id=1580271");
Expand Down

0 comments on commit c2c0118

Please sign in to comment.