From 0eeb784e2e5bef760ee44e6b5e38bd2c0d2bd6dd Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 13 Jan 2025 12:11:06 -0800 Subject: [PATCH 01/17] Disambiguate XPaths for children of BODY with id, class, or role attributes --- .../class-od-html-tag-processor.php | 62 +++++++++++++++---- 1 file changed, 50 insertions(+), 12 deletions(-) diff --git a/plugins/optimization-detective/class-od-html-tag-processor.php b/plugins/optimization-detective/class-od-html-tag-processor.php index 70bf7bc7f..1807b6ac3 100644 --- a/plugins/optimization-detective/class-od-html-tag-processor.php +++ b/plugins/optimization-detective/class-od-html-tag-processor.php @@ -123,7 +123,7 @@ final class OD_HTML_Tag_Processor extends WP_HTML_Tag_Processor { * @var string * @link https://github.com/WordPress/performance/issues/1787 */ - const XPATH_PATTERN = '^(/([a-zA-Z0-9:_-]+|\*\[\d+\]\[self::[a-zA-Z0-9:_-]+\]))+$'; + const XPATH_PATTERN = '^(/([a-zA-Z0-9:_-]+|\*\[\d+\]\[self::[a-zA-Z0-9:_-]+\])(\[@\w+.*?\])*)+$'; /** * Bookmark for the end of the HEAD. @@ -151,6 +151,14 @@ final class OD_HTML_Tag_Processor extends WP_HTML_Tag_Processor { */ private $open_stack_tags = array(); + /** + * Stack of the attributes for open tags. + * + * @since n.e.x.t + * @var array> + */ + private $open_stack_attributes = array(); + /** * Open stack indices. * @@ -168,7 +176,7 @@ final class OD_HTML_Tag_Processor extends WP_HTML_Tag_Processor { * populated back into `$this->open_stack_tags` and `$this->open_stack_indices`. * * @since 0.4.0 - * @var array + * @var array>, indices: int[]}> */ private $bookmarked_open_stacks = array(); @@ -291,8 +299,9 @@ public function next_token(): bool { $this->current_xpath = null; // Clear cache. ++$this->cursor_move_count; if ( ! parent::next_token() ) { - $this->open_stack_tags = array(); - $this->open_stack_indices = array(); + $this->open_stack_tags = array(); + $this->open_stack_attributes = array(); + $this->open_stack_indices = array(); // Mark that the end of the document was reached, meaning that get_modified_html() should now be able to append markup to the HEAD and the BODY. $this->reached_end_of_document = true; @@ -306,6 +315,7 @@ public function next_token(): bool { if ( $this->previous_tag_without_closer ) { array_pop( $this->open_stack_tags ); + array_pop( $this->open_stack_attributes ); } if ( ! $this->is_tag_closer() ) { @@ -317,6 +327,7 @@ public function next_token(): bool { $i = array_search( 'P', $this->open_stack_tags, true ); if ( false !== $i ) { array_splice( $this->open_stack_tags, (int) $i ); + array_splice( $this->open_stack_attributes, (int) $i ); array_splice( $this->open_stack_indices, count( $this->open_stack_tags ) + 1 ); } } @@ -324,6 +335,16 @@ public function next_token(): bool { $level = count( $this->open_stack_tags ); $this->open_stack_tags[] = $tag_name; + // Capture key attributes for each tag on the stack. This is used to further disambiguate XPaths, specifically for children of the BODY for now. + $attributes = array(); + foreach ( array( 'id', 'class', 'role' ) as $attribute_name ) { + $attribute_value = $this->get_attribute( $attribute_name ); + if ( null !== $attribute_value ) { + $attributes[ $attribute_name ] = $attribute_value; + } + } + $this->open_stack_attributes[] = $attributes; + if ( ! isset( $this->open_stack_indices[ $level ] ) ) { $this->open_stack_indices[ $level ] = 0; } else { @@ -347,6 +368,7 @@ public function next_token(): bool { } $popped_tag_name = array_pop( $this->open_stack_tags ); + array_pop( $this->open_stack_attributes ); if ( $popped_tag_name !== $tag_name ) { $this->warn( __METHOD__, @@ -464,8 +486,9 @@ public function get_current_depth(): int { public function seek( $bookmark_name ): bool { $result = parent::seek( $bookmark_name ); if ( $result ) { - $this->open_stack_tags = $this->bookmarked_open_stacks[ $bookmark_name ]['tags']; - $this->open_stack_indices = $this->bookmarked_open_stacks[ $bookmark_name ]['indices']; + $this->open_stack_tags = $this->bookmarked_open_stacks[ $bookmark_name ]['tags']; + $this->open_stack_attributes = $this->bookmarked_open_stacks[ $bookmark_name ]['attributes']; + $this->open_stack_indices = $this->bookmarked_open_stacks[ $bookmark_name ]['indices']; } return $result; } @@ -483,8 +506,9 @@ public function set_bookmark( $name ): bool { $result = parent::set_bookmark( $name ); if ( $result ) { $this->bookmarked_open_stacks[ $name ] = array( - 'tags' => $this->open_stack_tags, - 'indices' => $this->open_stack_indices, + 'tags' => $this->open_stack_tags, + 'attributes' => $this->open_stack_attributes, + 'indices' => $this->open_stack_indices, ); } return $result; @@ -520,11 +544,11 @@ public function release_bookmark( $name ): bool { * @since 0.4.0 * @since 0.9.0 Renamed from get_breadcrumbs() to get_indexed_breadcrumbs(). * - * @return Generator Breadcrumb. + * @return Generator}> Breadcrumb. */ private function get_indexed_breadcrumbs(): Generator { foreach ( $this->open_stack_tags as $i => $breadcrumb_tag_name ) { - yield array( $breadcrumb_tag_name, $this->open_stack_indices[ $i ] ); + yield array( $breadcrumb_tag_name, $this->open_stack_indices[ $i ], $this->open_stack_attributes[ $i ] ); } } @@ -574,9 +598,23 @@ private function is_foreign_element(): bool { public function get_xpath(): string { if ( null === $this->current_xpath ) { $this->current_xpath = ''; - foreach ( $this->get_indexed_breadcrumbs() as $i => list( $tag_name, $index ) ) { - if ( $i < 2 || ( 2 === $i && '/HTML/BODY' === $this->current_xpath ) ) { + foreach ( $this->get_indexed_breadcrumbs() as $i => list( $tag_name, $index, $attributes ) ) { + if ( $i < 2 ) { $this->current_xpath .= "/$tag_name"; + } elseif ( 2 === $i && '/HTML/BODY' === $this->current_xpath ) { + $segment = "/$tag_name"; + foreach ( $attributes as $attribute_name => $attribute_value ) { + if ( true === $attribute_value ) { + $segment .= sprintf( '[@%s]', $attribute_name ); + } else { + $segment .= sprintf( + "[@%s='%s']", + $attribute_name, + addcslashes( $attribute_value, '\'\\' ) // TODO: Verify escaping. + ); + } + } + $this->current_xpath .= $segment; } else { $this->current_xpath .= sprintf( '/*[%d][self::%s]', $index + 1, $tag_name ); } From 286d9cbc2cac6bb5cce031ee833955e9f3ec3fe9 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 13 Jan 2025 12:11:48 -0800 Subject: [PATCH 02/17] Update tests to incorporate new XPaths --- .../all-embeds-inside-viewport/expected.html | 90 +- .../all-embeds-inside-viewport/set-up.php | 2 +- .../nested-figure-embed/expected.html | 25 +- .../expected.html | 12 +- .../expected.html | 9 +- .../expected.html | 17 +- .../expected.html | 17 +- .../expected.html | 10 +- .../expected.html | 23 +- .../expected.html | 23 +- .../expected.html | 12 +- .../expected.html | 11 +- .../expected.html | 14 +- .../expected.html | 14 +- .../expected.html | 9 +- .../expected.html | 10 +- .../too-many-bookmarks/expected.html | 2 +- .../set-up.php | 4 +- .../expected.html | 2 +- .../set-up.php | 2 +- .../set-up.php | 6 +- .../set-up.php | 2 +- .../set-up.php | 14 +- .../expected.html | 4 +- .../set-up.php | 4 +- .../set-up.php | 2 +- .../expected.html | 10 +- .../set-up.php | 10 +- .../expected.html | 4 +- .../set-up.php | 8 +- .../expected.html | 4 +- .../set-up.php | 16 +- .../expected.html | 4 +- .../set-up.php | 16 +- .../set-up.php | 2 +- .../expected.html | 2 +- .../set-up.php | 4 +- .../set-up.php | 8 +- .../img-non-native-lazy-loading/set-up.php | 2 +- .../expected.html | 10 +- .../set-up.php | 8 +- .../expected.html | 10 +- .../set-up.php | 8 +- .../set-up.php | 2 +- .../expected.html | 8 +- .../test-cases/no-url-metrics/expected.html | 4 +- .../expected.html | 4 +- .../set-up.php | 4 +- .../expected.html | 2 +- .../set-up.php | 2 +- .../set-up.php | 2 +- .../set-up.php | 2 +- .../set-up.php | 2 +- .../responsive-background-images/set-up.php | 2 +- .../expected.html | 2 +- .../set-up.php | 2 +- .../expected.html | 2 +- .../set-up.php | 2 +- .../expected.html | 2 +- .../set-up.php | 2 +- .../expected.html | 2 +- .../set-up.php | 2 +- .../expected.html | 4 +- .../set-up.php | 8 +- .../expected.html | 4 +- .../set-up.php | 12 +- .../expected.html | 4 +- .../set-up.php | 6 +- .../image-prioritizer/tests/test-helper.php | 12 +- .../test-cases/many-images/expected.html | 2000 ++++++++--------- .../test-cases/no-url-metrics/expected.html | 2 +- .../tests/test-cases/video/expected.html | 2 +- .../test-cases/xhtml-response/expected.html | 2 +- .../test-class-od-html-tag-processor.php | 266 +-- 74 files changed, 1372 insertions(+), 1466 deletions(-) diff --git a/plugins/embed-optimizer/tests/test-cases/all-embeds-inside-viewport/expected.html b/plugins/embed-optimizer/tests/test-cases/all-embeds-inside-viewport/expected.html index cb8b50e3c..dcef822fc 100644 --- a/plugins/embed-optimizer/tests/test-cases/all-embeds-inside-viewport/expected.html +++ b/plugins/embed-optimizer/tests/test-cases/all-embeds-inside-viewport/expected.html @@ -3,58 +3,58 @@ ... @@ -83,14 +83,14 @@
-
+
-
+
@@ -98,49 +98,49 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
diff --git a/plugins/embed-optimizer/tests/test-cases/all-embeds-inside-viewport/set-up.php b/plugins/embed-optimizer/tests/test-cases/all-embeds-inside-viewport/set-up.php index 6ea4d7f7c..c7094d0d2 100644 --- a/plugins/embed-optimizer/tests/test-cases/all-embeds-inside-viewport/set-up.php +++ b/plugins/embed-optimizer/tests/test-cases/all-embeds-inside-viewport/set-up.php @@ -12,7 +12,7 @@ $elements[] = array_merge( $element_data, array( - 'xpath' => "/HTML/BODY/DIV/*[{$i}][self::FIGURE]/*[1][self::DIV]", + 'xpath' => "/HTML/BODY/DIV[@class='wp-site-blocks']/*[{$i}][self::FIGURE]/*[1][self::DIV]", ) ); } diff --git a/plugins/embed-optimizer/tests/test-cases/nested-figure-embed/expected.html b/plugins/embed-optimizer/tests/test-cases/nested-figure-embed/expected.html index ba37caa5c..4f0750df9 100644 --- a/plugins/embed-optimizer/tests/test-cases/nested-figure-embed/expected.html +++ b/plugins/embed-optimizer/tests/test-cases/nested-figure-embed/expected.html @@ -2,32 +2,19 @@ ... - - - - +
-
-
- +
+
+
-
+

So I heard you like FIGURE?

- +
Tagline from Figurine embed.
diff --git a/plugins/embed-optimizer/tests/test-cases/single-spotify-embed-outside-viewport-with-subsequent-script/expected.html b/plugins/embed-optimizer/tests/test-cases/single-spotify-embed-outside-viewport-with-subsequent-script/expected.html index 1921c4b47..16f181707 100644 --- a/plugins/embed-optimizer/tests/test-cases/single-spotify-embed-outside-viewport-with-subsequent-script/expected.html +++ b/plugins/embed-optimizer/tests/test-cases/single-spotify-embed-outside-viewport-with-subsequent-script/expected.html @@ -2,17 +2,11 @@ ... - - +
-
-
+
+
diff --git a/plugins/embed-optimizer/tests/test-cases/single-twitter-embed-inside-viewport-without-resized-data/expected.html b/plugins/embed-optimizer/tests/test-cases/single-twitter-embed-inside-viewport-without-resized-data/expected.html index e580503c3..a12e3ba20 100644 --- a/plugins/embed-optimizer/tests/test-cases/single-twitter-embed-inside-viewport-without-resized-data/expected.html +++ b/plugins/embed-optimizer/tests/test-cases/single-twitter-embed-inside-viewport-without-resized-data/expected.html @@ -2,17 +2,16 @@ ... - - - +
- +
- + + diff --git a/plugins/embed-optimizer/tests/test-cases/single-twitter-embed-inside-viewport/expected.html b/plugins/embed-optimizer/tests/test-cases/single-twitter-embed-inside-viewport/expected.html index a41674725..a12e3ba20 100644 --- a/plugins/embed-optimizer/tests/test-cases/single-twitter-embed-inside-viewport/expected.html +++ b/plugins/embed-optimizer/tests/test-cases/single-twitter-embed-inside-viewport/expected.html @@ -2,23 +2,16 @@ ... - - - - +
-
+
- +
- + + diff --git a/plugins/embed-optimizer/tests/test-cases/single-twitter-embed-outside-viewport-on-mobile/expected.html b/plugins/embed-optimizer/tests/test-cases/single-twitter-embed-outside-viewport-on-mobile/expected.html index 6c44678b8..a12e3ba20 100644 --- a/plugins/embed-optimizer/tests/test-cases/single-twitter-embed-outside-viewport-on-mobile/expected.html +++ b/plugins/embed-optimizer/tests/test-cases/single-twitter-embed-outside-viewport-on-mobile/expected.html @@ -2,23 +2,16 @@ ... - - - - +
-
+
- +
- + + diff --git a/plugins/embed-optimizer/tests/test-cases/single-twitter-embed-outside-viewport/expected.html b/plugins/embed-optimizer/tests/test-cases/single-twitter-embed-outside-viewport/expected.html index d55d88ef8..a12e3ba20 100644 --- a/plugins/embed-optimizer/tests/test-cases/single-twitter-embed-outside-viewport/expected.html +++ b/plugins/embed-optimizer/tests/test-cases/single-twitter-embed-outside-viewport/expected.html @@ -2,16 +2,10 @@ ... - - +
-
+
diff --git a/plugins/embed-optimizer/tests/test-cases/single-wordpress-tv-embed-inside-viewport/expected.html b/plugins/embed-optimizer/tests/test-cases/single-wordpress-tv-embed-inside-viewport/expected.html index 24ec36b5b..664283a38 100644 --- a/plugins/embed-optimizer/tests/test-cases/single-wordpress-tv-embed-inside-viewport/expected.html +++ b/plugins/embed-optimizer/tests/test-cases/single-wordpress-tv-embed-inside-viewport/expected.html @@ -2,26 +2,17 @@ ... - - - - - - +
-
-
- - +
+
+ +
- + + diff --git a/plugins/embed-optimizer/tests/test-cases/single-wordpress-tv-embed-outside-viewport-on-mobile/expected.html b/plugins/embed-optimizer/tests/test-cases/single-wordpress-tv-embed-outside-viewport-on-mobile/expected.html index cf6d4a12e..664283a38 100644 --- a/plugins/embed-optimizer/tests/test-cases/single-wordpress-tv-embed-outside-viewport-on-mobile/expected.html +++ b/plugins/embed-optimizer/tests/test-cases/single-wordpress-tv-embed-outside-viewport-on-mobile/expected.html @@ -2,26 +2,17 @@ ... - - - - - - +
-
-
- - +
+
+ +
- + + diff --git a/plugins/embed-optimizer/tests/test-cases/single-wordpress-tv-embed-outside-viewport/expected.html b/plugins/embed-optimizer/tests/test-cases/single-wordpress-tv-embed-outside-viewport/expected.html index 7b706664c..664283a38 100644 --- a/plugins/embed-optimizer/tests/test-cases/single-wordpress-tv-embed-outside-viewport/expected.html +++ b/plugins/embed-optimizer/tests/test-cases/single-wordpress-tv-embed-outside-viewport/expected.html @@ -2,17 +2,11 @@ ... - - +
-
-
+
+
diff --git a/plugins/embed-optimizer/tests/test-cases/single-youtube-embed-inside-viewport-with-only-mobile-url-metrics/expected.html b/plugins/embed-optimizer/tests/test-cases/single-youtube-embed-inside-viewport-with-only-mobile-url-metrics/expected.html index 400790d6e..295671002 100644 --- a/plugins/embed-optimizer/tests/test-cases/single-youtube-embed-inside-viewport-with-only-mobile-url-metrics/expected.html +++ b/plugins/embed-optimizer/tests/test-cases/single-youtube-embed-inside-viewport-with-only-mobile-url-metrics/expected.html @@ -2,16 +2,11 @@ ... - - - - +
-
-
+
+
diff --git a/plugins/embed-optimizer/tests/test-cases/single-youtube-embed-inside-viewport/expected.html b/plugins/embed-optimizer/tests/test-cases/single-youtube-embed-inside-viewport/expected.html index d159a1ddf..92094c1fc 100644 --- a/plugins/embed-optimizer/tests/test-cases/single-youtube-embed-inside-viewport/expected.html +++ b/plugins/embed-optimizer/tests/test-cases/single-youtube-embed-inside-viewport/expected.html @@ -2,20 +2,12 @@ ... - - - - +
-
+
- +
diff --git a/plugins/embed-optimizer/tests/test-cases/single-youtube-embed-outside-viewport-on-mobile/expected.html b/plugins/embed-optimizer/tests/test-cases/single-youtube-embed-outside-viewport-on-mobile/expected.html index e207715e3..92094c1fc 100644 --- a/plugins/embed-optimizer/tests/test-cases/single-youtube-embed-outside-viewport-on-mobile/expected.html +++ b/plugins/embed-optimizer/tests/test-cases/single-youtube-embed-outside-viewport-on-mobile/expected.html @@ -2,20 +2,12 @@ ... - - - - +
-
+
- +
diff --git a/plugins/embed-optimizer/tests/test-cases/single-youtube-embed-outside-viewport-with-only-mobile-url-metrics/expected.html b/plugins/embed-optimizer/tests/test-cases/single-youtube-embed-outside-viewport-with-only-mobile-url-metrics/expected.html index 7badfa2ad..295671002 100644 --- a/plugins/embed-optimizer/tests/test-cases/single-youtube-embed-outside-viewport-with-only-mobile-url-metrics/expected.html +++ b/plugins/embed-optimizer/tests/test-cases/single-youtube-embed-outside-viewport-with-only-mobile-url-metrics/expected.html @@ -2,14 +2,11 @@ ... - - +
-
-
+
+
diff --git a/plugins/embed-optimizer/tests/test-cases/single-youtube-embed-outside-viewport/expected.html b/plugins/embed-optimizer/tests/test-cases/single-youtube-embed-outside-viewport/expected.html index 58f90072c..92094c1fc 100644 --- a/plugins/embed-optimizer/tests/test-cases/single-youtube-embed-outside-viewport/expected.html +++ b/plugins/embed-optimizer/tests/test-cases/single-youtube-embed-outside-viewport/expected.html @@ -2,16 +2,10 @@ ... - - +
-
+
diff --git a/plugins/embed-optimizer/tests/test-cases/too-many-bookmarks/expected.html b/plugins/embed-optimizer/tests/test-cases/too-many-bookmarks/expected.html index 999512d0a..6d13da4a2 100644 --- a/plugins/embed-optimizer/tests/test-cases/too-many-bookmarks/expected.html +++ b/plugins/embed-optimizer/tests/test-cases/too-many-bookmarks/expected.html @@ -6,7 +6,7 @@
-
+
diff --git a/plugins/image-prioritizer/tests/test-cases/background-image-outside-viewport-on-all-breakpoints-but-not-desktop-with-fully-populated-sample-data/set-up.php b/plugins/image-prioritizer/tests/test-cases/background-image-outside-viewport-on-all-breakpoints-but-not-desktop-with-fully-populated-sample-data/set-up.php index 048869df9..5839f6eb3 100644 --- a/plugins/image-prioritizer/tests/test-cases/background-image-outside-viewport-on-all-breakpoints-but-not-desktop-with-fully-populated-sample-data/set-up.php +++ b/plugins/image-prioritizer/tests/test-cases/background-image-outside-viewport-on-all-breakpoints-but-not-desktop-with-fully-populated-sample-data/set-up.php @@ -26,7 +26,7 @@ static function () use ( $breakpoint_max_widths ) { 'viewport_width' => $non_desktop_viewport_width, 'elements' => array( array( - 'xpath' => '/HTML/BODY/DIV/*[2][self::DIV]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[2][self::DIV]', 'isLCP' => false, 'intersectionRatio' => 0.0, 'intersectionRect' => $outside_viewport_rect, @@ -47,7 +47,7 @@ static function () use ( $breakpoint_max_widths ) { 'viewport_width' => 1000, 'elements' => array( array( - 'xpath' => '/HTML/BODY/DIV/*[2][self::DIV]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[2][self::DIV]', 'isLCP' => false, 'intersectionRatio' => 0.3, ), diff --git a/plugins/image-prioritizer/tests/test-cases/background-image-outside-viewport-with-desktop-metrics-missing/expected.html b/plugins/image-prioritizer/tests/test-cases/background-image-outside-viewport-with-desktop-metrics-missing/expected.html index 4a2eaac7a..e89bacdf9 100644 --- a/plugins/image-prioritizer/tests/test-cases/background-image-outside-viewport-with-desktop-metrics-missing/expected.html +++ b/plugins/image-prioritizer/tests/test-cases/background-image-outside-viewport-with-desktop-metrics-missing/expected.html @@ -6,7 +6,7 @@

Pretend this is a super long paragraph that pushes the next div out of the initial viewport.

-
This is so background!
+
This is so background!
diff --git a/plugins/image-prioritizer/tests/test-cases/background-image-outside-viewport-with-desktop-metrics-missing/set-up.php b/plugins/image-prioritizer/tests/test-cases/background-image-outside-viewport-with-desktop-metrics-missing/set-up.php index 6653f015f..dc4dc10f4 100644 --- a/plugins/image-prioritizer/tests/test-cases/background-image-outside-viewport-with-desktop-metrics-missing/set-up.php +++ b/plugins/image-prioritizer/tests/test-cases/background-image-outside-viewport-with-desktop-metrics-missing/set-up.php @@ -24,7 +24,7 @@ static function () use ( $breakpoint_max_widths ) { 'viewport_width' => $non_desktop_viewport_width, 'elements' => array( array( - 'xpath' => '/HTML/BODY/DIV/*[2][self::DIV]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[2][self::DIV]', 'isLCP' => false, 'intersectionRatio' => 0.0, 'intersectionRect' => $outside_viewport_rect, diff --git a/plugins/image-prioritizer/tests/test-cases/common-lcp-background-image-and-lazy-loaded-background-image-outside-viewport-with-fully-populated-sample-data/set-up.php b/plugins/image-prioritizer/tests/test-cases/common-lcp-background-image-and-lazy-loaded-background-image-outside-viewport-with-fully-populated-sample-data/set-up.php index 3e76d4ce7..fe81ed23d 100644 --- a/plugins/image-prioritizer/tests/test-cases/common-lcp-background-image-and-lazy-loaded-background-image-outside-viewport-with-fully-populated-sample-data/set-up.php +++ b/plugins/image-prioritizer/tests/test-cases/common-lcp-background-image-and-lazy-loaded-background-image-outside-viewport-with-fully-populated-sample-data/set-up.php @@ -10,18 +10,18 @@ $test_case->populate_url_metrics( array( array( - 'xpath' => '/HTML/BODY/DIV/*[1][self::DIV]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::DIV]', 'isLCP' => true, ), array( - 'xpath' => '/HTML/BODY/DIV/*[3][self::DIV]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[3][self::DIV]', 'isLCP' => false, 'intersectionRatio' => 0.0, 'intersectionRect' => $outside_viewport_rect, 'boundingClientRect' => $outside_viewport_rect, ), array( - 'xpath' => '/HTML/BODY/DIV/*[4][self::DIV]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[4][self::DIV]', 'isLCP' => false, 'intersectionRatio' => 0.0, 'intersectionRect' => $outside_viewport_rect, diff --git a/plugins/image-prioritizer/tests/test-cases/common-lcp-background-image-with-fully-populated-sample-data/set-up.php b/plugins/image-prioritizer/tests/test-cases/common-lcp-background-image-with-fully-populated-sample-data/set-up.php index cb39822c3..6107e8cd8 100644 --- a/plugins/image-prioritizer/tests/test-cases/common-lcp-background-image-with-fully-populated-sample-data/set-up.php +++ b/plugins/image-prioritizer/tests/test-cases/common-lcp-background-image-with-fully-populated-sample-data/set-up.php @@ -3,7 +3,7 @@ $test_case->populate_url_metrics( array( array( - 'xpath' => '/HTML/BODY/DIV/*[1][self::DIV]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::DIV]', 'isLCP' => true, ), ) diff --git a/plugins/image-prioritizer/tests/test-cases/common-lcp-image-and-lazy-loaded-image-outside-viewport-with-fully-populated-sample-data/set-up.php b/plugins/image-prioritizer/tests/test-cases/common-lcp-image-and-lazy-loaded-image-outside-viewport-with-fully-populated-sample-data/set-up.php index ee940eae5..2bf089a7c 100644 --- a/plugins/image-prioritizer/tests/test-cases/common-lcp-image-and-lazy-loaded-image-outside-viewport-with-fully-populated-sample-data/set-up.php +++ b/plugins/image-prioritizer/tests/test-cases/common-lcp-image-and-lazy-loaded-image-outside-viewport-with-fully-populated-sample-data/set-up.php @@ -17,41 +17,41 @@ 'viewport_width' => $viewport_width, 'elements' => array( array( - 'xpath' => '/HTML/BODY/DIV/*[1][self::DIV]/*[1][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::DIV]/*[1][self::IMG]', 'isLCP' => true, ), array( - 'xpath' => '/HTML/BODY/DIV/*[1][self::DIV]/*[2][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::DIV]/*[2][self::IMG]', 'isLCP' => false, 'intersectionRatio' => 0.0, // Subsequent carousel slide. ), array( - 'xpath' => '/HTML/BODY/DIV/*[1][self::DIV]/*[3][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::DIV]/*[3][self::IMG]', 'isLCP' => false, 'intersectionRatio' => 0.0, // Subsequent carousel slide. ), array( - 'xpath' => '/HTML/BODY/DIV/*[3][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[3][self::IMG]', 'isLCP' => false, 'intersectionRatio' => 0 === $i ? 0.5 : 0.0, // Make sure that the _max_ intersection ratio is considered. ), // All are outside all initial viewports. array( - 'xpath' => '/HTML/BODY/DIV/*[5][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[5][self::IMG]', 'isLCP' => false, 'intersectionRatio' => 0.0, 'intersectionRect' => $outside_viewport_rect, 'boundingClientRect' => $outside_viewport_rect, ), array( - 'xpath' => '/HTML/BODY/DIV/*[6][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[6][self::IMG]', 'isLCP' => false, 'intersectionRatio' => 0.0, 'intersectionRect' => $outside_viewport_rect, 'boundingClientRect' => $outside_viewport_rect, ), array( - 'xpath' => '/HTML/BODY/DIV/*[7][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[7][self::IMG]', 'isLCP' => false, 'intersectionRatio' => 0.0, 'intersectionRect' => $outside_viewport_rect, diff --git a/plugins/image-prioritizer/tests/test-cases/common-lcp-image-with-fully-incomplete-sample-data/expected.html b/plugins/image-prioritizer/tests/test-cases/common-lcp-image-with-fully-incomplete-sample-data/expected.html index 51215d05b..6a5d64be0 100644 --- a/plugins/image-prioritizer/tests/test-cases/common-lcp-image-with-fully-incomplete-sample-data/expected.html +++ b/plugins/image-prioritizer/tests/test-cases/common-lcp-image-with-fully-incomplete-sample-data/expected.html @@ -6,8 +6,8 @@
- Foo - Bar + Foo + Bar
diff --git a/plugins/image-prioritizer/tests/test-cases/common-lcp-image-with-fully-incomplete-sample-data/set-up.php b/plugins/image-prioritizer/tests/test-cases/common-lcp-image-with-fully-incomplete-sample-data/set-up.php index 2666fb6ce..16b9cc441 100644 --- a/plugins/image-prioritizer/tests/test-cases/common-lcp-image-with-fully-incomplete-sample-data/set-up.php +++ b/plugins/image-prioritizer/tests/test-cases/common-lcp-image-with-fully-incomplete-sample-data/set-up.php @@ -12,11 +12,11 @@ 'viewport_width' => 1000, 'elements' => array( array( - 'xpath' => '/HTML/BODY/DIV/*[1][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::IMG]', 'isLCP' => true, ), array( - 'xpath' => '/HTML/BODY/DIV/*[2][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[2][self::IMG]', 'isLCP' => false, ), ), diff --git a/plugins/image-prioritizer/tests/test-cases/common-lcp-image-with-stale-sample-data/set-up.php b/plugins/image-prioritizer/tests/test-cases/common-lcp-image-with-stale-sample-data/set-up.php index 60f03a4d6..b6f41c93b 100644 --- a/plugins/image-prioritizer/tests/test-cases/common-lcp-image-with-stale-sample-data/set-up.php +++ b/plugins/image-prioritizer/tests/test-cases/common-lcp-image-with-stale-sample-data/set-up.php @@ -3,7 +3,7 @@ $test_case->populate_url_metrics( array( array( - 'xpath' => '/HTML/BODY/DIV/*[1][self::IMG]', // Note: This is intentionally not reflecting the IMG in the HTML below. + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::IMG]', // Note: This is intentionally not reflecting the IMG in the HTML below. 'isLCP' => true, ), ) diff --git a/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-all-breakpoints/expected.html b/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-all-breakpoints/expected.html index 4e1b0de92..1c31d64e1 100644 --- a/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-all-breakpoints/expected.html +++ b/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-all-breakpoints/expected.html @@ -10,11 +10,11 @@
- Mobile Logo - Phablet Logo - Tablet Logo - Desktop Logo - Desktop Logo + Mobile Logo + Phablet Logo + Tablet Logo + Desktop Logo + Desktop Logo
diff --git a/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-all-breakpoints/set-up.php b/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-all-breakpoints/set-up.php index 4f33479ff..c8f325838 100644 --- a/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-all-breakpoints/set-up.php +++ b/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-all-breakpoints/set-up.php @@ -13,23 +13,23 @@ static function () use ( $breakpoint_max_widths ) { $elements = array( array( 'isLCP' => false, - 'xpath' => '/HTML/BODY/DIV/*[1][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::IMG]', ), array( 'isLCP' => false, - 'xpath' => '/HTML/BODY/DIV/*[2][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[2][self::IMG]', ), array( 'isLCP' => false, - 'xpath' => '/HTML/BODY/DIV/*[3][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[3][self::IMG]', ), array( 'isLCP' => false, - 'xpath' => '/HTML/BODY/DIV/*[4][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[4][self::IMG]', ), array( 'isLCP' => false, - 'xpath' => '/HTML/BODY/DIV/*[5][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[5][self::IMG]', ), ); $elements[ $i ]['isLCP'] = true; diff --git a/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-non-consecutive-viewport-groups-with-missing-data-for-middle-group/expected.html b/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-non-consecutive-viewport-groups-with-missing-data-for-middle-group/expected.html index 075275898..255e096a8 100644 --- a/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-non-consecutive-viewport-groups-with-missing-data-for-middle-group/expected.html +++ b/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-non-consecutive-viewport-groups-with-missing-data-for-middle-group/expected.html @@ -8,8 +8,8 @@
- Mobile Logo - Desktop Logo + Mobile Logo + Desktop Logo
diff --git a/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-non-consecutive-viewport-groups-with-missing-data-for-middle-group/set-up.php b/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-non-consecutive-viewport-groups-with-missing-data-for-middle-group/set-up.php index 3f0b67e8c..de5207f4d 100644 --- a/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-non-consecutive-viewport-groups-with-missing-data-for-middle-group/set-up.php +++ b/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-non-consecutive-viewport-groups-with-missing-data-for-middle-group/set-up.php @@ -8,12 +8,12 @@ 'elements' => array( array( 'isLCP' => true, - 'xpath' => '/HTML/BODY/DIV/*[1][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::IMG]', 'intersectionRatio' => 1.0, ), array( 'isLCP' => false, - 'xpath' => '/HTML/BODY/DIV/*[2][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[2][self::IMG]', 'intersectionRatio' => 0.0, ), ), @@ -28,12 +28,12 @@ 'elements' => array( array( 'isLCP' => false, - 'xpath' => '/HTML/BODY/DIV/*[1][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::IMG]', 'intersectionRatio' => 0.0, ), array( 'isLCP' => true, - 'xpath' => '/HTML/BODY/DIV/*[2][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[2][self::IMG]', 'intersectionRatio' => 1.0, ), ), diff --git a/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-two-non-consecutive-breakpoints-and-one-is-stale/expected.html b/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-two-non-consecutive-breakpoints-and-one-is-stale/expected.html index cd3ac1393..f30af0fb8 100644 --- a/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-two-non-consecutive-breakpoints-and-one-is-stale/expected.html +++ b/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-two-non-consecutive-breakpoints-and-one-is-stale/expected.html @@ -6,9 +6,9 @@
- Mobile Logo + Mobile Logo

New paragraph since URL Metrics were captured!

- Desktop Logo + Desktop Logo
diff --git a/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-two-non-consecutive-breakpoints-and-one-is-stale/set-up.php b/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-two-non-consecutive-breakpoints-and-one-is-stale/set-up.php index 4b7db6cc5..6228509cd 100644 --- a/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-two-non-consecutive-breakpoints-and-one-is-stale/set-up.php +++ b/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-two-non-consecutive-breakpoints-and-one-is-stale/set-up.php @@ -15,11 +15,11 @@ static function () { 'elements' => array( array( 'isLCP' => true, - 'xpath' => '/HTML/BODY/DIV/*[1][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::IMG]', ), array( 'isLCP' => false, - 'xpath' => '/HTML/BODY/DIV/*[2][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[2][self::IMG]', ), ), ) @@ -33,11 +33,11 @@ static function () { 'elements' => array( array( 'isLCP' => false, - 'xpath' => '/HTML/BODY/DIV/*[1][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::IMG]', ), array( 'isLCP' => false, - 'xpath' => '/HTML/BODY/DIV/*[2][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[2][self::IMG]', ), ), ) @@ -51,11 +51,11 @@ static function () { 'elements' => array( array( 'isLCP' => false, - 'xpath' => '/HTML/BODY/DIV/*[1][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::IMG]', ), array( 'isLCP' => true, - 'xpath' => '/HTML/BODY/DIV/*[2][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[2][self::IMG]', ), ), ) @@ -69,11 +69,11 @@ static function () { 'elements' => array( array( 'isLCP' => false, - 'xpath' => '/HTML/BODY/DIV/*[1][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::IMG]', ), array( 'isLCP' => false, - 'xpath' => '/HTML/BODY/DIV/*[2][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[2][self::IMG]', ), ), ) diff --git a/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-two-non-consecutive-breakpoints/expected.html b/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-two-non-consecutive-breakpoints/expected.html index cbd0491a9..f64ff1dc5 100644 --- a/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-two-non-consecutive-breakpoints/expected.html +++ b/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-two-non-consecutive-breakpoints/expected.html @@ -7,8 +7,8 @@
- Mobile Logo - Desktop Logo + Mobile Logo + Desktop Logo
diff --git a/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-two-non-consecutive-breakpoints/set-up.php b/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-two-non-consecutive-breakpoints/set-up.php index 9c12a4adf..5853037f8 100644 --- a/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-two-non-consecutive-breakpoints/set-up.php +++ b/plugins/image-prioritizer/tests/test-cases/different-lcp-elements-for-two-non-consecutive-breakpoints/set-up.php @@ -15,11 +15,11 @@ static function () { 'elements' => array( array( 'isLCP' => true, - 'xpath' => '/HTML/BODY/DIV/*[1][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::IMG]', ), array( 'isLCP' => false, - 'xpath' => '/HTML/BODY/DIV/*[2][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[2][self::IMG]', ), ), ) @@ -33,11 +33,11 @@ static function () { 'elements' => array( array( 'isLCP' => false, - 'xpath' => '/HTML/BODY/DIV/*[1][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::IMG]', ), array( 'isLCP' => false, - 'xpath' => '/HTML/BODY/DIV/*[2][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[2][self::IMG]', ), ), ) @@ -51,11 +51,11 @@ static function () { 'elements' => array( array( 'isLCP' => false, - 'xpath' => '/HTML/BODY/DIV/*[1][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::IMG]', ), array( 'isLCP' => true, - 'xpath' => '/HTML/BODY/DIV/*[2][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[2][self::IMG]', ), ), ) @@ -69,11 +69,11 @@ static function () { 'elements' => array( array( 'isLCP' => false, - 'xpath' => '/HTML/BODY/DIV/*[1][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::IMG]', ), array( 'isLCP' => false, - 'xpath' => '/HTML/BODY/DIV/*[2][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[2][self::IMG]', ), ), ) diff --git a/plugins/image-prioritizer/tests/test-cases/fetch-priority-high-already-on-common-lcp-image-with-fully-populated-sample-data/set-up.php b/plugins/image-prioritizer/tests/test-cases/fetch-priority-high-already-on-common-lcp-image-with-fully-populated-sample-data/set-up.php index 47f81633e..950f2c642 100644 --- a/plugins/image-prioritizer/tests/test-cases/fetch-priority-high-already-on-common-lcp-image-with-fully-populated-sample-data/set-up.php +++ b/plugins/image-prioritizer/tests/test-cases/fetch-priority-high-already-on-common-lcp-image-with-fully-populated-sample-data/set-up.php @@ -4,7 +4,7 @@ array( array( 'isLCP' => true, - 'xpath' => '/HTML/BODY/DIV/*[1][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::IMG]', ), ) ); diff --git a/plugins/image-prioritizer/tests/test-cases/fetch-priority-high-on-lcp-image-common-on-mobile-and-desktop-with-url-metrics-missing-in-other-groups/expected.html b/plugins/image-prioritizer/tests/test-cases/fetch-priority-high-on-lcp-image-common-on-mobile-and-desktop-with-url-metrics-missing-in-other-groups/expected.html index 1f46f3468..ba24685f4 100644 --- a/plugins/image-prioritizer/tests/test-cases/fetch-priority-high-on-lcp-image-common-on-mobile-and-desktop-with-url-metrics-missing-in-other-groups/expected.html +++ b/plugins/image-prioritizer/tests/test-cases/fetch-priority-high-on-lcp-image-common-on-mobile-and-desktop-with-url-metrics-missing-in-other-groups/expected.html @@ -7,7 +7,7 @@
- Foo + Foo
diff --git a/plugins/image-prioritizer/tests/test-cases/fetch-priority-high-on-lcp-image-common-on-mobile-and-desktop-with-url-metrics-missing-in-other-groups/set-up.php b/plugins/image-prioritizer/tests/test-cases/fetch-priority-high-on-lcp-image-common-on-mobile-and-desktop-with-url-metrics-missing-in-other-groups/set-up.php index dba2b3d3e..52c292d65 100644 --- a/plugins/image-prioritizer/tests/test-cases/fetch-priority-high-on-lcp-image-common-on-mobile-and-desktop-with-url-metrics-missing-in-other-groups/set-up.php +++ b/plugins/image-prioritizer/tests/test-cases/fetch-priority-high-on-lcp-image-common-on-mobile-and-desktop-with-url-metrics-missing-in-other-groups/set-up.php @@ -16,7 +16,7 @@ static function () use ( $breakpoint_max_widths ) { 'viewport_width' => 375, 'elements' => array( array( - 'xpath' => '/HTML/BODY/DIV/*[1][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::IMG]', 'isLCP' => true, ), ), @@ -31,7 +31,7 @@ static function () use ( $breakpoint_max_widths ) { 'viewport_width' => 1000, 'elements' => array( array( - 'xpath' => '/HTML/BODY/DIV/*[1][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::IMG]', 'isLCP' => true, ), ), diff --git a/plugins/image-prioritizer/tests/test-cases/images-located-above-or-along-initial-viewport/set-up.php b/plugins/image-prioritizer/tests/test-cases/images-located-above-or-along-initial-viewport/set-up.php index d8cadae66..4f7d08a6a 100644 --- a/plugins/image-prioritizer/tests/test-cases/images-located-above-or-along-initial-viewport/set-up.php +++ b/plugins/image-prioritizer/tests/test-cases/images-located-above-or-along-initial-viewport/set-up.php @@ -33,28 +33,28 @@ 'viewport_width' => $viewport_width, 'elements' => array( array( - 'xpath' => '/HTML/BODY/DIV/*[1][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::IMG]', 'isLCP' => false, 'intersectionRatio' => 0.0, 'intersectionRect' => $above_viewport_rect, 'boundingClientRect' => $above_viewport_rect, ), array( - 'xpath' => '/HTML/BODY/DIV/*[2][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[2][self::IMG]', 'isLCP' => false, 'intersectionRatio' => 0.0, 'intersectionRect' => $left_of_viewport_rect, 'boundingClientRect' => $left_of_viewport_rect, ), array( - 'xpath' => '/HTML/BODY/DIV/*[3][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[3][self::IMG]', 'isLCP' => false, 'intersectionRatio' => 0.0, 'intersectionRect' => $right_of_viewport_rect, 'boundingClientRect' => $right_of_viewport_rect, ), array( - 'xpath' => '/HTML/BODY/DIV/*[4][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[4][self::IMG]', 'isLCP' => false, 'intersectionRatio' => 0.0, 'intersectionRect' => $below_viewport_rect, diff --git a/plugins/image-prioritizer/tests/test-cases/img-non-native-lazy-loading/set-up.php b/plugins/image-prioritizer/tests/test-cases/img-non-native-lazy-loading/set-up.php index 88c966d7c..b0bd77140 100644 --- a/plugins/image-prioritizer/tests/test-cases/img-non-native-lazy-loading/set-up.php +++ b/plugins/image-prioritizer/tests/test-cases/img-non-native-lazy-loading/set-up.php @@ -10,7 +10,7 @@ 'viewport_width' => 1000, 'elements' => array( array( - 'xpath' => '/HTML/BODY/DIV/*[1][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::IMG]', 'isLCP' => true, ), ), diff --git a/plugins/image-prioritizer/tests/test-cases/multiple-videos-on-all-breakpoints/expected.html b/plugins/image-prioritizer/tests/test-cases/multiple-videos-on-all-breakpoints/expected.html index cf7beb429..6fcd36906 100644 --- a/plugins/image-prioritizer/tests/test-cases/multiple-videos-on-all-breakpoints/expected.html +++ b/plugins/image-prioritizer/tests/test-cases/multiple-videos-on-all-breakpoints/expected.html @@ -6,11 +6,11 @@
- - - - - + + + + +
diff --git a/plugins/image-prioritizer/tests/test-cases/multiple-videos-on-all-breakpoints/set-up.php b/plugins/image-prioritizer/tests/test-cases/multiple-videos-on-all-breakpoints/set-up.php index 245364eb4..83100c805 100644 --- a/plugins/image-prioritizer/tests/test-cases/multiple-videos-on-all-breakpoints/set-up.php +++ b/plugins/image-prioritizer/tests/test-cases/multiple-videos-on-all-breakpoints/set-up.php @@ -18,25 +18,25 @@ static function () use ( $breakpoint_max_widths ) { 'elements' => array( array( 'isLCP' => true, - 'xpath' => '/HTML/BODY/DIV/*[1][self::VIDEO]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::VIDEO]', 'boundingClientRect' => $test_case->get_sample_dom_rect(), 'intersectionRatio' => 1.0, ), array( 'isLCP' => false, - 'xpath' => '/HTML/BODY/DIV/*[2][self::VIDEO]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[2][self::VIDEO]', 'boundingClientRect' => $test_case->get_sample_dom_rect(), 'intersectionRatio' => 0.1, ), array( 'isLCP' => false, - 'xpath' => '/HTML/BODY/DIV/*[3][self::VIDEO]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[3][self::VIDEO]', 'boundingClientRect' => $test_case->get_sample_dom_rect(), 'intersectionRatio' => 0.0, ), array( 'isLCP' => false, - 'xpath' => '/HTML/BODY/DIV/*[4][self::VIDEO]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[4][self::VIDEO]', 'boundingClientRect' => $test_case->get_sample_dom_rect(), 'intersectionRatio' => 0.0, ), diff --git a/plugins/image-prioritizer/tests/test-cases/multiple-videos-with-desktop-metrics-missing/expected.html b/plugins/image-prioritizer/tests/test-cases/multiple-videos-with-desktop-metrics-missing/expected.html index d6b78a2d9..c3ccef493 100644 --- a/plugins/image-prioritizer/tests/test-cases/multiple-videos-with-desktop-metrics-missing/expected.html +++ b/plugins/image-prioritizer/tests/test-cases/multiple-videos-with-desktop-metrics-missing/expected.html @@ -6,11 +6,11 @@
- - - - - + + + + +
diff --git a/plugins/image-prioritizer/tests/test-cases/multiple-videos-with-desktop-metrics-missing/set-up.php b/plugins/image-prioritizer/tests/test-cases/multiple-videos-with-desktop-metrics-missing/set-up.php index 65b95a21c..606b43c88 100644 --- a/plugins/image-prioritizer/tests/test-cases/multiple-videos-with-desktop-metrics-missing/set-up.php +++ b/plugins/image-prioritizer/tests/test-cases/multiple-videos-with-desktop-metrics-missing/set-up.php @@ -18,25 +18,25 @@ static function () use ( $breakpoint_max_widths ) { 'elements' => array( array( 'isLCP' => true, - 'xpath' => '/HTML/BODY/DIV/*[1][self::VIDEO]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::VIDEO]', 'boundingClientRect' => $test_case->get_sample_dom_rect(), 'intersectionRatio' => 1.0, ), array( 'isLCP' => false, - 'xpath' => '/HTML/BODY/DIV/*[2][self::VIDEO]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[2][self::VIDEO]', 'boundingClientRect' => $test_case->get_sample_dom_rect(), 'intersectionRatio' => 0.1, ), array( 'isLCP' => false, - 'xpath' => '/HTML/BODY/DIV/*[3][self::VIDEO]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[3][self::VIDEO]', 'boundingClientRect' => $test_case->get_sample_dom_rect(), 'intersectionRatio' => 0.0, ), array( 'isLCP' => false, - 'xpath' => '/HTML/BODY/DIV/*[4][self::VIDEO]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[4][self::VIDEO]', 'boundingClientRect' => $test_case->get_sample_dom_rect(), 'intersectionRatio' => 0.0, ), diff --git a/plugins/image-prioritizer/tests/test-cases/no-lcp-image-or-background-image-outside-viewport-with-populated-url-metrics/set-up.php b/plugins/image-prioritizer/tests/test-cases/no-lcp-image-or-background-image-outside-viewport-with-populated-url-metrics/set-up.php index c0a5bf173..145581fa7 100644 --- a/plugins/image-prioritizer/tests/test-cases/no-lcp-image-or-background-image-outside-viewport-with-populated-url-metrics/set-up.php +++ b/plugins/image-prioritizer/tests/test-cases/no-lcp-image-or-background-image-outside-viewport-with-populated-url-metrics/set-up.php @@ -3,7 +3,7 @@ $test_case->populate_url_metrics( array( array( - 'xpath' => '/HTML/BODY/DIV/*[1][self::H1]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::H1]', 'isLCP' => true, ), ) diff --git a/plugins/image-prioritizer/tests/test-cases/no-url-metrics-but-server-side-heuristics-added-fetchpriority-high/expected.html b/plugins/image-prioritizer/tests/test-cases/no-url-metrics-but-server-side-heuristics-added-fetchpriority-high/expected.html index f85d6cf74..5b735e433 100644 --- a/plugins/image-prioritizer/tests/test-cases/no-url-metrics-but-server-side-heuristics-added-fetchpriority-high/expected.html +++ b/plugins/image-prioritizer/tests/test-cases/no-url-metrics-but-server-side-heuristics-added-fetchpriority-high/expected.html @@ -5,10 +5,10 @@
- Foo - Bar - Baz - Qux + Foo + Bar + Baz + Qux
diff --git a/plugins/image-prioritizer/tests/test-cases/no-url-metrics/expected.html b/plugins/image-prioritizer/tests/test-cases/no-url-metrics/expected.html index b62547c48..e65e561ff 100644 --- a/plugins/image-prioritizer/tests/test-cases/no-url-metrics/expected.html +++ b/plugins/image-prioritizer/tests/test-cases/no-url-metrics/expected.html @@ -5,9 +5,9 @@
- Foo + Foo

Pretend this is a super long paragraph that pushes the next div out of the initial viewport.

-
This is so background!
+
This is so background!
diff --git a/plugins/image-prioritizer/tests/test-cases/only-mobile-and-desktop-groups-are-populated/expected.html b/plugins/image-prioritizer/tests/test-cases/only-mobile-and-desktop-groups-are-populated/expected.html index 9d86483b0..1323295b4 100644 --- a/plugins/image-prioritizer/tests/test-cases/only-mobile-and-desktop-groups-are-populated/expected.html +++ b/plugins/image-prioritizer/tests/test-cases/only-mobile-and-desktop-groups-are-populated/expected.html @@ -23,14 +23,14 @@

Last Post

First Post

This post does have a featured image, and the server-side heuristics in WordPress cause it to get fetchpriority=high, but it should not have this since it is out of the viewport on mobile.

Pretend this is a super long paragraph that pushes the next div out of the initial viewport.

-
This is so background!
+
This is so background!
diff --git a/plugins/image-prioritizer/tests/test-cases/only-mobile-and-desktop-groups-are-populated/set-up.php b/plugins/image-prioritizer/tests/test-cases/only-mobile-and-desktop-groups-are-populated/set-up.php index 29244432e..72ff40f7e 100644 --- a/plugins/image-prioritizer/tests/test-cases/only-mobile-and-desktop-groups-are-populated/set-up.php +++ b/plugins/image-prioritizer/tests/test-cases/only-mobile-and-desktop-groups-are-populated/set-up.php @@ -27,12 +27,12 @@ static function () { 'viewport_width' => $viewport_width, 'elements' => array( array( - 'xpath' => '/HTML/BODY/DIV/*[2][self::MAIN]/*[2][self::ARTICLE]/*[2][self::FIGURE]/*[1][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[2][self::MAIN]/*[2][self::ARTICLE]/*[2][self::FIGURE]/*[1][self::IMG]', 'isLCP' => $viewport_width > 600, 'intersectionRatio' => $viewport_width > 600 ? 1.0 : 0.1, ), array( - 'xpath' => '/HTML/BODY/DIV/*[2][self::MAIN]/*[4][self::DIV]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[2][self::MAIN]/*[4][self::DIV]', 'isLCP' => false, 'intersectionRatio' => 0.0, 'intersectionRect' => $outside_viewport_rect, diff --git a/plugins/image-prioritizer/tests/test-cases/picture-element-as-lcp-tablet-and-desktop-metrics-missing/expected.html b/plugins/image-prioritizer/tests/test-cases/picture-element-as-lcp-tablet-and-desktop-metrics-missing/expected.html index 3c091020b..d3119732b 100644 --- a/plugins/image-prioritizer/tests/test-cases/picture-element-as-lcp-tablet-and-desktop-metrics-missing/expected.html +++ b/plugins/image-prioritizer/tests/test-cases/picture-element-as-lcp-tablet-and-desktop-metrics-missing/expected.html @@ -9,7 +9,7 @@ - Foo + Foo
diff --git a/plugins/image-prioritizer/tests/test-cases/picture-element-as-lcp-tablet-and-desktop-metrics-missing/set-up.php b/plugins/image-prioritizer/tests/test-cases/picture-element-as-lcp-tablet-and-desktop-metrics-missing/set-up.php index 414d90ee6..32acd76fd 100644 --- a/plugins/image-prioritizer/tests/test-cases/picture-element-as-lcp-tablet-and-desktop-metrics-missing/set-up.php +++ b/plugins/image-prioritizer/tests/test-cases/picture-element-as-lcp-tablet-and-desktop-metrics-missing/set-up.php @@ -22,7 +22,7 @@ static function () use ( $breakpoint_max_widths ) { 'viewport_width' => $viewport_width, 'elements' => array( array( - 'xpath' => '/HTML/BODY/DIV/*[1][self::PICTURE]/*[3][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::PICTURE]/*[3][self::IMG]', 'isLCP' => true, ), ), diff --git a/plugins/image-prioritizer/tests/test-cases/picture-element-with-lcp-image-and-fully-populated-sample-data/set-up.php b/plugins/image-prioritizer/tests/test-cases/picture-element-with-lcp-image-and-fully-populated-sample-data/set-up.php index cb673b547..2500623b0 100644 --- a/plugins/image-prioritizer/tests/test-cases/picture-element-with-lcp-image-and-fully-populated-sample-data/set-up.php +++ b/plugins/image-prioritizer/tests/test-cases/picture-element-with-lcp-image-and-fully-populated-sample-data/set-up.php @@ -12,7 +12,7 @@ static function () use ( $breakpoint_max_widths ) { $test_case->populate_url_metrics( array( array( - 'xpath' => '/HTML/BODY/DIV/*[1][self::PICTURE]/*[2][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::PICTURE]/*[2][self::IMG]', 'isLCP' => true, ), ) diff --git a/plugins/image-prioritizer/tests/test-cases/picture-element-with-source-having-media-attribute/set-up.php b/plugins/image-prioritizer/tests/test-cases/picture-element-with-source-having-media-attribute/set-up.php index cb673b547..2500623b0 100644 --- a/plugins/image-prioritizer/tests/test-cases/picture-element-with-source-having-media-attribute/set-up.php +++ b/plugins/image-prioritizer/tests/test-cases/picture-element-with-source-having-media-attribute/set-up.php @@ -12,7 +12,7 @@ static function () use ( $breakpoint_max_widths ) { $test_case->populate_url_metrics( array( array( - 'xpath' => '/HTML/BODY/DIV/*[1][self::PICTURE]/*[2][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::PICTURE]/*[2][self::IMG]', 'isLCP' => true, ), ) diff --git a/plugins/image-prioritizer/tests/test-cases/picture-element-with-source-missing-type-attribute/set-up.php b/plugins/image-prioritizer/tests/test-cases/picture-element-with-source-missing-type-attribute/set-up.php index cb673b547..2500623b0 100644 --- a/plugins/image-prioritizer/tests/test-cases/picture-element-with-source-missing-type-attribute/set-up.php +++ b/plugins/image-prioritizer/tests/test-cases/picture-element-with-source-missing-type-attribute/set-up.php @@ -12,7 +12,7 @@ static function () use ( $breakpoint_max_widths ) { $test_case->populate_url_metrics( array( array( - 'xpath' => '/HTML/BODY/DIV/*[1][self::PICTURE]/*[2][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::PICTURE]/*[2][self::IMG]', 'isLCP' => true, ), ) diff --git a/plugins/image-prioritizer/tests/test-cases/responsive-background-images/set-up.php b/plugins/image-prioritizer/tests/test-cases/responsive-background-images/set-up.php index f31160ed0..e79cafd61 100644 --- a/plugins/image-prioritizer/tests/test-cases/responsive-background-images/set-up.php +++ b/plugins/image-prioritizer/tests/test-cases/responsive-background-images/set-up.php @@ -26,7 +26,7 @@ static function () use ( $mobile_breakpoint, $tablet_breakpoint ): array { array( 'viewport_width' => $viewport_width, 'element' => array( - 'xpath' => sprintf( '/HTML/BODY/DIV/*[%d][self::DIV]', $div_index + 1 ), + 'xpath' => sprintf( '/HTML/BODY/DIV[@id=\'page\']/*[%d][self::DIV]', $div_index + 1 ), 'isLCP' => true, ), ) diff --git a/plugins/image-prioritizer/tests/test-cases/url-metric-only-captured-for-one-breakpoint/expected.html b/plugins/image-prioritizer/tests/test-cases/url-metric-only-captured-for-one-breakpoint/expected.html index d0dd1329d..0e045721b 100644 --- a/plugins/image-prioritizer/tests/test-cases/url-metric-only-captured-for-one-breakpoint/expected.html +++ b/plugins/image-prioritizer/tests/test-cases/url-metric-only-captured-for-one-breakpoint/expected.html @@ -8,7 +8,7 @@
- Foo + Foo
diff --git a/plugins/image-prioritizer/tests/test-cases/url-metric-only-captured-for-one-breakpoint/set-up.php b/plugins/image-prioritizer/tests/test-cases/url-metric-only-captured-for-one-breakpoint/set-up.php index 568a112cd..68190d206 100644 --- a/plugins/image-prioritizer/tests/test-cases/url-metric-only-captured-for-one-breakpoint/set-up.php +++ b/plugins/image-prioritizer/tests/test-cases/url-metric-only-captured-for-one-breakpoint/set-up.php @@ -7,7 +7,7 @@ 'viewport_width' => 400, 'element' => array( 'isLCP' => true, - 'xpath' => '/HTML/BODY/DIV/*[1][self::IMG]', + 'xpath' => '/HTML/BODY/DIV[@id=\'page\']/*[1][self::IMG]', ), ) ) diff --git a/plugins/image-prioritizer/tests/test-cases/video-with-large-poster-and-desktop-url-metrics-collected/expected.html b/plugins/image-prioritizer/tests/test-cases/video-with-large-poster-and-desktop-url-metrics-collected/expected.html index 648472749..659752173 100644 --- a/plugins/image-prioritizer/tests/test-cases/video-with-large-poster-and-desktop-url-metrics-collected/expected.html +++ b/plugins/image-prioritizer/tests/test-cases/video-with-large-poster-and-desktop-url-metrics-collected/expected.html @@ -5,7 +5,7 @@
-