Changeset 279444 in webkit


Ignore:
Timestamp:
Jun 30, 2021, 4:54:40 PM (4 years ago)
Author:
Megan Gardner
Message:

Add ID and versioning support for AppHighlights
https://bugs.webkit.org/show_bug.cgi?id=227279

Reviewed by Tim Horton.

Source/WebCore:

AppHighlights.AppHighlightRestoreFromStorage
AppHighlights.AppHighlightCreateAndRestoreAndDropBytes
AppHighlights.AppHighlightCreateAndRestoreWithLaterVersion
AppHighlights.AppHighlightCreateAndRestoreWithExtraBytes
AppHighlights.AppHighlightRestoreFromStorageV0
AppHighlights.AppHighlightRestoreFromStorageV1

Reformat the storage of Highlight Data to allow for accurate deletion of active
highlights, as well as making them more robust and future-proof. Support decoding v0
highlights as well.

  • Modules/highlight/AppHighlightRangeData.cpp:

(WebCore::AppHighlightRangeData::NodePathComponent::decode):
(WebCore::AppHighlightRangeData::encode const):
(WebCore::AppHighlightRangeData::decode):

  • Modules/highlight/AppHighlightRangeData.h:

(WebCore::AppHighlightRangeData::NodePathComponent::NodePathComponent):
(WebCore::AppHighlightRangeData::AppHighlightRangeData):
(WebCore::AppHighlightRangeData::identifier const):
(WebCore::AppHighlightRangeData::startOffset const):
(WebCore::AppHighlightRangeData::endOffset const):

  • Modules/highlight/AppHighlightStorage.cpp:

(WebCore::createAppHighlightRangeData):

Source/WebKit:

Reformat the storage of Highlight Data to allow for accurate deletion of active
highlights, as well as making them more robust and future-proof.

Also found an issue with creating SharedBuffers from the memory map, in that the ipcHandle size
should be used instead of the sharedMemory->size().

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::restoreAppHighlightsAndScrollToIndex):

Source/WTF:

Allow PersistentDecoders to rewind, to help support v0 highlight data.

  • wtf/persistence/PersistentDecoder.cpp:

(WTF::Persistence::Decoder::Decoder):
(WTF::Persistence::Decoder::rewind):

  • wtf/persistence/PersistentDecoder.h:

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/WKAppHighlights.mm:

(TestWebKitAPI::createAppHighlightWithHTML):
(TestWebKitAPI::createWebViewForAppHighlightsWithHTML):
(TestWebKitAPI::TEST):

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r279439 r279444  
     12021-06-30  Megan Gardner  <megan_gardner@apple.com>
     2
     3        Add ID and versioning support for AppHighlights
     4        https://bugs.webkit.org/show_bug.cgi?id=227279
     5
     6        Reviewed by Tim Horton.
     7
     8        Allow PersistentDecoders to rewind, to help support v0 highlight data.
     9
     10        * wtf/persistence/PersistentDecoder.cpp:
     11        (WTF::Persistence::Decoder::Decoder):
     12        (WTF::Persistence::Decoder::rewind):
     13        * wtf/persistence/PersistentDecoder.h:
     14
    1152021-06-30  Ryosuke Niwa  <rniwa@webkit.org>
    216
  • trunk/Source/WTF/wtf/persistence/PersistentDecoder.cpp

    r278253 r279444  
    6767    memcpy(data, buffer, size);
    6868    return true;
     69}
     70
     71bool Decoder::rewind(size_t size)
     72{
     73    if (m_bufferPosition - size >= m_buffer) {
     74        m_bufferPosition -= size;
     75        return true;
     76    }
     77    return false;
    6978}
    7079
  • trunk/Source/WTF/wtf/persistence/PersistentDecoder.h

    r278253 r279444  
    4141    size_t length() const { return m_bufferEnd - m_buffer; }
    4242    size_t currentOffset() const { return m_bufferPosition - m_buffer; }
     43   
     44    WTF_EXPORT_PRIVATE WARN_UNUSED_RETURN bool rewind(size_t);
    4345
    4446    WTF_EXPORT_PRIVATE WARN_UNUSED_RETURN bool verifyChecksum();
  • trunk/Source/WebCore/ChangeLog

    r279443 r279444  
     12021-06-30  Megan Gardner  <megan_gardner@apple.com>
     2
     3        Add ID and versioning support for AppHighlights
     4        https://bugs.webkit.org/show_bug.cgi?id=227279
     5
     6        Reviewed by Tim Horton.
     7
     8        AppHighlights.AppHighlightRestoreFromStorage
     9        AppHighlights.AppHighlightCreateAndRestoreAndDropBytes
     10        AppHighlights.AppHighlightCreateAndRestoreWithLaterVersion
     11        AppHighlights.AppHighlightCreateAndRestoreWithExtraBytes
     12        AppHighlights.AppHighlightRestoreFromStorageV0
     13        AppHighlights.AppHighlightRestoreFromStorageV1
     14
     15        Reformat the storage of Highlight Data to allow for accurate deletion of active
     16        highlights, as well as making them more robust and future-proof. Support decoding v0
     17        highlights as well.
     18
     19        * Modules/highlight/AppHighlightRangeData.cpp:
     20        (WebCore::AppHighlightRangeData::NodePathComponent::decode):
     21        (WebCore::AppHighlightRangeData::encode const):
     22        (WebCore::AppHighlightRangeData::decode):
     23        * Modules/highlight/AppHighlightRangeData.h:
     24        (WebCore::AppHighlightRangeData::NodePathComponent::NodePathComponent):
     25        (WebCore::AppHighlightRangeData::AppHighlightRangeData):
     26        (WebCore::AppHighlightRangeData::identifier const):
     27        (WebCore::AppHighlightRangeData::startOffset const):
     28        (WebCore::AppHighlightRangeData::endOffset const):
     29        * Modules/highlight/AppHighlightStorage.cpp:
     30        (WebCore::createAppHighlightRangeData):
     31
    1322021-06-30  Ryosuke Niwa  <rniwa@webkit.org>
    233
  • trunk/Source/WebCore/Modules/highlight/AppHighlightRangeData.cpp

    r278253 r279444  
    4242namespace WebCore {
    4343
     44constexpr uint64_t highlightFileSignature = 0x4141504832303231; // File Signature  (A)pple(AP)plication(H)ighlights(2021)
     45
    4446std::optional<AppHighlightRangeData> AppHighlightRangeData::create(const SharedBuffer& buffer)
    4547{
     
    8284        return std::nullopt;
    8385
    84     std::optional<unsigned> pathIndex;
     86    std::optional<uint32_t> pathIndex;
    8587    decoder >> pathIndex;
    8688    if (!pathIndex)
     
    9294template<class Encoder> void AppHighlightRangeData::encode(Encoder& encoder) const
    9395{
     96    static_assert(!Encoder::isIPCEncoder, "AppHighlightRangeData should not be used by IPC::Encoder");
     97    constexpr uint64_t currentAppHighlightVersion = 1;
     98   
     99    encoder << highlightFileSignature;
     100    encoder << currentAppHighlightVersion;
     101    encoder << m_identifier;
    94102    encoder << m_text;
    95103    encoder << m_startContainer;
     
    101109template<class Decoder> std::optional<AppHighlightRangeData> AppHighlightRangeData::decode(Decoder& decoder)
    102110{
     111    static_assert(!Decoder::isIPCDecoder, "AppHighlightRangeData should not be used by IPC::Decoder");
     112   
     113    std::optional<uint64_t> version;
     114   
     115    std::optional<uint64_t> decodedHighlightFileSignature;
     116    decoder >> decodedHighlightFileSignature;
     117    if (!decodedHighlightFileSignature)
     118        return std::nullopt;
     119    if (decodedHighlightFileSignature != highlightFileSignature) {
     120        if (!decoder.rewind(sizeof(highlightFileSignature)))
     121            return std::nullopt;
     122        version = 0;
     123    }
     124   
     125    std::optional<String> identifier;
     126    if (version)
     127        identifier = nullString();
     128    else {
     129        decoder >> version;
     130        if (!version)
     131            return std::nullopt;
     132       
     133        decoder >> identifier;
     134        if (!identifier)
     135            return std::nullopt;
     136    }
     137
    103138    std::optional<String> text;
    104139    decoder >> text;
     
    111146        return std::nullopt;
    112147
    113     std::optional<unsigned> startOffset;
     148    std::optional<uint32_t> startOffset;
    114149    decoder >> startOffset;
    115150    if (!startOffset)
     
    121156        return std::nullopt;
    122157
    123     std::optional<unsigned> endOffset;
     158    std::optional<uint32_t> endOffset;
    124159    decoder >> endOffset;
    125160    if (!endOffset)
    126161        return std::nullopt;
    127162
    128 
    129     return {{ WTFMove(*text), WTFMove(*startContainer), *startOffset, WTFMove(*endContainer), *endOffset }};
     163    return {{ WTFMove(*identifier), WTFMove(*text), WTFMove(*startContainer), *startOffset, WTFMove(*endContainer), *endOffset }};
    130164}
    131165
  • trunk/Source/WebCore/Modules/highlight/AppHighlightRangeData.h

    r278340 r279444  
    4444        String nodeName;
    4545        String textData;
    46         unsigned pathIndex { 0 };
     46        uint32_t pathIndex { 0 };
    4747
    48         NodePathComponent(String&& elementIdentifier, String&& name, String&& data, unsigned index)
     48        NodePathComponent(String&& elementIdentifier, String&& name, String&& data, uint32_t index)
    4949            : identifier(WTFMove(elementIdentifier))
    5050            , nodeName(WTFMove(name))
     
    5454        }
    5555
    56         NodePathComponent(const String& elementIdentifier, const String& name, const String& data, unsigned index)
     56        NodePathComponent(const String& elementIdentifier, const String& name, const String& data, uint32_t index)
    5757            : identifier(elementIdentifier)
    5858            , nodeName(name)
     
    8080    AppHighlightRangeData(const AppHighlightRangeData&) = default;
    8181    AppHighlightRangeData() = default;
    82     AppHighlightRangeData(String&& text, NodePath&& startContainer, unsigned startOffset, NodePath&& endContainer, unsigned endOffset)
    83         : m_text(WTFMove(text))
     82    AppHighlightRangeData(String&& identifier, String&& text, NodePath&& startContainer, uint64_t startOffset, NodePath&& endContainer, uint64_t endOffset)
     83        : m_identifier(WTFMove(identifier))
     84        , m_text(WTFMove(text))
    8485        , m_startContainer(WTFMove(startContainer))
    8586        , m_startOffset(startOffset)
     
    8990    }
    9091
    91     AppHighlightRangeData(const String& text, const NodePath& startContainer, unsigned startOffset, const NodePath& endContainer, unsigned endOffset)
    92         : m_text(text)
     92    AppHighlightRangeData(const String& identifier, const String& text, const NodePath& startContainer, uint64_t startOffset, const NodePath& endContainer, uint64_t endOffset)
     93        : m_identifier(identifier)
     94        , m_text(text)
    9395        , m_startContainer(startContainer)
    9496        , m_startOffset(startOffset)
     
    98100    }
    99101
     102    const String& identifier() const { return m_identifier; }
    100103    const String& text() const { return m_text; }
    101104    const NodePath& startContainer() const { return m_startContainer; }
    102     unsigned startOffset() const { return m_startOffset; }
     105    uint32_t startOffset() const { return m_startOffset; }
    103106    const NodePath& endContainer() const { return m_endContainer; }
    104     unsigned endOffset() const { return m_endOffset; }
     107    uint32_t endOffset() const { return m_endOffset; }
    105108
    106109    template<class Encoder> void encode(Encoder&) const;
     
    110113
    111114private:
     115    String m_identifier;
    112116    String m_text;
    113117    NodePath m_startContainer;
    114     unsigned m_startOffset { 0 };
     118    uint32_t m_startOffset { 0 };
    115119    NodePath m_endContainer;
    116     unsigned m_endOffset { 0 };
     120    uint32_t m_endOffset { 0 };
    117121};
    118122
  • trunk/Source/WebCore/Modules/highlight/AppHighlightStorage.cpp

    r278253 r279444  
    4444#include "TextIndicator.h"
    4545#include "TextIterator.h"
     46#include <wtf/UUID.h>
    4647
    4748namespace WebCore {
     
    204205    auto text = plainText(range);
    205206    text.truncate(textPreviewLength);
     207    auto identifier = createCanonicalUUIDString();
     208
    206209    return {
     210        identifier,
    207211        text,
    208212        makeNodePath(&range.startContainer()),
  • trunk/Source/WebKit/ChangeLog

    r279432 r279444  
     12021-06-30  Megan Gardner  <megan_gardner@apple.com>
     2
     3        Add ID and versioning support for AppHighlights
     4        https://bugs.webkit.org/show_bug.cgi?id=227279
     5
     6        Reviewed by Tim Horton.
     7
     8        Reformat the storage of Highlight Data to allow for accurate deletion of active
     9        highlights, as well as making them more robust and future-proof.
     10
     11        Also found an issue with creating SharedBuffers from the memory map, in that the ipcHandle size
     12        should be used instead of the sharedMemory->size().
     13
     14        * WebProcess/WebPage/WebPage.cpp:
     15        (WebKit::WebPage::restoreAppHighlightsAndScrollToIndex):
     16
    1172021-06-30  Truitt Savell  <tsavell@apple.com>
    218
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r279420 r279444  
    76187618            continue;
    76197619
    7620         document->appHighlightStorage().restoreAndScrollToAppHighlight(SharedBuffer::create(static_cast<const uint8_t*>(sharedMemory->data()), sharedMemory->size()), i == index ? ScrollToHighlight::Yes : ScrollToHighlight::No);
     7620        document->appHighlightStorage().restoreAndScrollToAppHighlight(SharedBuffer::create(static_cast<const uint8_t*>(sharedMemory->data()), ipcHandle.dataSize), i == index ? ScrollToHighlight::Yes : ScrollToHighlight::No);
    76217621        i++;
    76227622    }
  • trunk/Tools/ChangeLog

    r279423 r279444  
     12021-06-30  Megan Gardner  <megan_gardner@apple.com>
     2
     3        Add ID and versioning support for AppHighlights
     4        https://bugs.webkit.org/show_bug.cgi?id=227279
     5
     6        Reviewed by Tim Horton.
     7
     8        * TestWebKitAPI/Tests/WebKitCocoa/WKAppHighlights.mm:
     9        (TestWebKitAPI::createAppHighlightWithHTML):
     10        (TestWebKitAPI::createWebViewForAppHighlightsWithHTML):
     11        (TestWebKitAPI::TEST):
     12
    1132021-06-30  Wenson Hsieh  <wenson_hsieh@apple.com>
    214
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAppHighlights.mm

    r276347 r279444  
    5757namespace TestWebKitAPI {
    5858
    59 TEST(AppHighlights, AppHighlightCreateAndRestore)
     59RetainPtr<_WKAppHighlight> createAppHighlightWithHTML(NSString *HTMLString, NSString *javaScript, NSString *highlightText)
    6060{
    6161    WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
    6262    auto delegate = adoptNS([[AppHighlightDelegate alloc] init]);
    6363    auto webViewCreate = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration]);
    64     auto webViewRestore = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration]);
    6564    [webViewCreate _setAppHighlightDelegate:delegate.get()];
    66     [webViewCreate synchronouslyLoadHTMLString:@"Test"];
    67     [webViewCreate stringByEvaluatingJavaScript:@"document.execCommand('SelectAll')"];
    68     __block bool finished = NO;
     65    [webViewCreate synchronouslyLoadHTMLString:HTMLString];
     66    [webViewCreate stringByEvaluatingJavaScript:javaScript];
     67    __block RetainPtr<_WKAppHighlight> resultHighlight;
     68    __block bool done = false;
    6969    [delegate setStoreAppHighlightCallback:^(WKWebView *delegateWebView, _WKAppHighlight *highlight, BOOL inNewGroup, BOOL requestOriginatedInApp) {
    7070        EXPECT_EQ(delegateWebView, webViewCreate.get());
    7171        EXPECT_NOT_NULL(highlight);
    72         EXPECT_WK_STREQ(highlight.text, @"Test");
     72        EXPECT_WK_STREQ(highlight.text, highlightText);
    7373        EXPECT_NOT_NULL(highlight.highlight);
    74        
    75         [webViewRestore synchronouslyLoadHTMLString:@"Test"];
    76         [webViewRestore _restoreAppHighlights:@[ highlight.highlight ]];
    77        
    78         TestWebKitAPI::Util::waitForConditionWithLogging([&] () -> bool {
    79             return [webViewRestore stringByEvaluatingJavaScript:@"internals.numberOfAppHighlights()"].intValue == 1;
    80         }, 2, @"Expected Highlights to be populated.");
    81        
    82         finished = YES;
     74        resultHighlight = highlight;
     75        done = true;
    8376    }];
    8477    [webViewCreate _addAppHighlight];
    85     TestWebKitAPI::Util::run(&finished);
     78    TestWebKitAPI::Util::run(&done);
     79    return resultHighlight;
     80}
     81
     82RetainPtr<WKWebView> createWebViewForAppHighlightsWithHTML(NSString *HTMLString)
     83{
     84    WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
     85    auto webViewRestore = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration]);
     86    [webViewRestore synchronouslyLoadHTMLString:HTMLString];
     87   
     88    return webViewRestore;
     89}
     90
     91TEST(AppHighlights, AppHighlightCreateAndRestore)
     92{
     93    auto highlight = createAppHighlightWithHTML(@"Test", @"document.execCommand('SelectAll')", @"Test");
     94    auto webViewRestore = createWebViewForAppHighlightsWithHTML(@"Test");
     95   
     96    [webViewRestore _restoreAppHighlights:@[[highlight highlight]]];
     97   
     98    TestWebKitAPI::Util::waitForConditionWithLogging([&] () -> bool {
     99        return [webViewRestore stringByEvaluatingJavaScript:@"internals.numberOfAppHighlights()"].intValue == 1;
     100    }, 2, @"Expected Highlights to be populated.");
    86101}
    87102
    88103TEST(AppHighlights, AppHighlightCreateAndRestoreAndScroll)
    89104{
    90     WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
    91     auto delegate = adoptNS([[AppHighlightDelegate alloc] init]);
    92     auto webViewCreate = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration]);
     105    auto highlight = createAppHighlightWithHTML(@"<div style='height: 10000px'></div>Test", @"document.execCommand('SelectAll')", @"Test");
     106    auto webViewRestore = createWebViewForAppHighlightsWithHTML(@"<div style='height: 10000px'></div>Test");
     107
     108    [webViewRestore _restoreAndScrollToAppHighlight:[highlight highlight]];
     109
     110    TestWebKitAPI::Util::waitForConditionWithLogging([&] () -> bool {
     111        return [webViewRestore stringByEvaluatingJavaScript:@"internals.numberOfAppHighlights()"].intValue == 1;
     112    }, 2, @"Expected Highlights to be populated.");
     113    EXPECT_NE(0, [[webViewRestore objectByEvaluatingJavaScript:@"pageYOffset"] floatValue]);
     114}
     115
     116TEST(AppHighlights, AppHighlightRestoreFailure)
     117{
     118    auto highlight = createAppHighlightWithHTML(@"Test", @"document.execCommand('SelectAll')", @"Test");
     119    auto webViewRestore = createWebViewForAppHighlightsWithHTML(@"Not The Same");
     120   
     121    [webViewRestore _restoreAppHighlights:@[[highlight highlight]]];
     122   
     123    TestWebKitAPI::Util::waitForConditionWithLogging([&] () -> bool {
     124        return ![webViewRestore stringByEvaluatingJavaScript:@"internals.numberOfAppHighlights()"].intValue;
     125    }, 2, @"Expected Highlights not to be populated.");
     126}
     127
     128// Ensure that future versions of the blob format can add additional data and still be decoded successfully by version of WebKit that only know about the current format.
     129TEST(AppHighlights, AppHighlightCreateAndRestoreWithExtraBytes)
     130{
     131    auto highlight = createAppHighlightWithHTML(@"Test", @"document.execCommand('SelectAll')", @"Test");
     132    auto webViewRestore = createWebViewForAppHighlightsWithHTML(@"Test");
     133       
     134    NSMutableData *modifiedHighlightData = [NSMutableData dataWithData: [highlight highlight] ];
     135    [modifiedHighlightData appendData:[@"TestV2Data" dataUsingEncoding:NSUTF8StringEncoding]];
     136   
     137    [webViewRestore synchronouslyLoadHTMLString:@"Test"];
     138    [webViewRestore _restoreAppHighlights:@[ modifiedHighlightData ]];
     139   
     140    TestWebKitAPI::Util::waitForConditionWithLogging([&] () -> bool {
     141        return [webViewRestore stringByEvaluatingJavaScript:@"internals.numberOfAppHighlights()"].intValue == 1;
     142    }, 2, @"Expected Highlights to be populated.");
     143}
     144
     145// Older versions of WebKit need to be able to decode blobs encoded on newer versions of WebKit, so ensure that is possible.
     146TEST(AppHighlights, AppHighlightCreateAndRestoreWithLaterVersion)
     147{
     148    auto highlight = createAppHighlightWithHTML(@"Test", @"document.execCommand('SelectAll')", @"Test");
     149    auto webViewRestore = createWebViewForAppHighlightsWithHTML(@"Test");
     150       
     151    uint64_t maximumVersion = std::numeric_limits<uint64_t>::max();
     152    NSData *versionData = [NSData dataWithBytes:&maximumVersion length:sizeof(maximumVersion)];
     153    NSMutableData *modifiedHighlightData = [NSMutableData dataWithData:[highlight highlight]];
     154
     155    [modifiedHighlightData replaceBytesInRange:NSMakeRange(sizeof(uint64_t), sizeof(maximumVersion)) withBytes:versionData];
     156
     157    [webViewRestore synchronouslyLoadHTMLString:@"Test"];
     158    [webViewRestore _restoreAppHighlights:@[ modifiedHighlightData ]];
     159   
     160    TestWebKitAPI::Util::waitForConditionWithLogging([&] () -> bool {
     161        return [webViewRestore stringByEvaluatingJavaScript:@"internals.numberOfAppHighlights()"].intValue == 1;
     162    }, 2, @"Expected Highlights to be populated.");
     163}
     164
     165// Ensure that shorter data blobs will correctly fail to decode.
     166TEST(AppHighlights, AppHighlightCreateAndRestoreAndDropBytes)
     167{
     168    auto highlight = createAppHighlightWithHTML(@"Test", @"document.execCommand('SelectAll')", @"Test");
     169    auto webViewRestore = createWebViewForAppHighlightsWithHTML(@"Test");
     170       
     171    NSMutableData *modifiedHighlightData = [NSMutableData dataWithBytes:[highlight highlight].bytes length:[highlight highlight].length / 2];
     172
     173    [webViewRestore synchronouslyLoadHTMLString:@"Test"];
     174    [webViewRestore _restoreAppHighlights:@[ modifiedHighlightData ]];
     175   
     176    TestWebKitAPI::Util::waitForConditionWithLogging([&] () -> bool {
     177        return ![webViewRestore stringByEvaluatingJavaScript:@"internals.numberOfAppHighlights()"].intValue;
     178    }, 2, @"Expected Highlights not to be populated.");
     179}
     180
     181// Ensure that the original data format will always be able to be decoded in the future.
     182TEST(AppHighlights, AppHighlightRestoreFromStorageV0)
     183{
     184    WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
     185    const unsigned char bytes[] = {0x04, 0x00, 0x00, 0x00, 0x01, 0x54, 0x65, 0x73, 0x74, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x05, 0x00, 0x00, 0x00, 0x01, 0x23, 0x74, 0x65, 0x78, 0x74, 0x04, 0x00, 0x00, 0x00, 0x01, 0x54, 0x65, 0x73, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x05, 0x00, 0x00, 0x00, 0x01, 0x23, 0x74, 0x65, 0x78, 0x74, 0x04, 0x00, 0x00, 0x00, 0x01, 0x54, 0x65, 0x73, 0x74, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00};
     186   
     187    NSData *storedData = [NSData dataWithBytes:&bytes length:87];
     188
    93189    auto webViewRestore = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration]);
    94     [webViewCreate _setAppHighlightDelegate:delegate.get()];
    95     [webViewCreate synchronouslyLoadHTMLString:@"<div style='height: 1000px'></div>Test"];
    96     [webViewCreate stringByEvaluatingJavaScript:@"document.execCommand('SelectAll')"];
    97     __block bool finished = NO;
    98     [delegate setStoreAppHighlightCallback:^(WKWebView *delegateWebView, _WKAppHighlight *highlight, BOOL inNewGroup, BOOL requestOriginatedInApp) {
    99         EXPECT_EQ(delegateWebView, webViewCreate.get());
    100         EXPECT_NOT_NULL(highlight);
    101         EXPECT_WK_STREQ(highlight.text, @"Test");
    102         EXPECT_NOT_NULL(highlight.highlight);
    103        
    104         [webViewRestore synchronouslyLoadHTMLString:@"<div style='height: 1000px'></div>Test"];
    105         [webViewRestore _restoreAndScrollToAppHighlight:highlight.highlight];
    106        
    107         TestWebKitAPI::Util::waitForConditionWithLogging([&] () -> bool {
    108             return [webViewRestore stringByEvaluatingJavaScript:@"internals.numberOfAppHighlights()"].intValue == 1;
    109         }, 2, @"Expected Highlights to be populated.");
    110         EXPECT_NE(0, [[webViewRestore objectByEvaluatingJavaScript:@"pageYOffset"] floatValue]);
    111        
    112         finished = YES;
    113     }];
    114     [webViewCreate _addAppHighlight];
    115     TestWebKitAPI::Util::run(&finished);
    116 }
    117 
    118 TEST(AppHighlights, AppHighlightRestoreFailure)
    119 {
    120     WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
    121     auto delegate = adoptNS([[AppHighlightDelegate alloc] init]);
    122     auto webViewCreate = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration]);
     190
     191    [webViewRestore synchronouslyLoadHTMLString:@"Test"];
     192    [webViewRestore _restoreAppHighlights:@[ storedData ]];
     193   
     194    TestWebKitAPI::Util::waitForConditionWithLogging([&] () -> bool {
     195        return [webViewRestore stringByEvaluatingJavaScript:@"internals.numberOfAppHighlights()"].intValue == 1;
     196    }, 2, @"Expected Highlights to be populated.");
     197}
     198
     199
     200// Ensure that the V1 data format will always be able to be decoded in the future.
     201TEST(AppHighlights, AppHighlightRestoreFromStorageV1)
     202{
     203    WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
     204    const unsigned char bytes[] = {0x31, 0x32, 0x30, 0x32, 0x48, 0x50, 0x41, 0x41, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x01, 0x31, 0x36, 0x30, 0x61, 0x36, 0x30, 0x31, 0x62, 0x2d, 0x31, 0x62, 0x37, 0x32, 0x2d, 0x34, 0x31, 0x31, 0x38, 0x2d, 0x62, 0x36, 0x64, 0x31, 0x2d, 0x39, 0x30, 0x32, 0x62, 0x37, 0x34, 0x66, 0x65, 0x61, 0x36, 0x36, 0x31, 0x04, 0x00, 0x00, 0x00, 0x01, 0x54, 0x65, 0x73, 0x74, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x05, 0x00, 0x00, 0x00, 0x01, 0x23, 0x74, 0x65, 0x78, 0x74, 0x04, 0x00, 0x00, 0x00, 0x01, 0x54, 0x65, 0x73, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x05, 0x00, 0x00, 0x00, 0x01, 0x23, 0x74, 0x65, 0x78, 0x74, 0x04, 0x00, 0x00, 0x00, 0x01, 0x54, 0x65, 0x73, 0x74, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00};
     205   
     206    NSData *storedData = [NSData dataWithBytes:&bytes length:144];
     207
    123208    auto webViewRestore = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration]);
    124     [webViewCreate _setAppHighlightDelegate:delegate.get()];
    125     [webViewCreate synchronouslyLoadHTMLString:@"Test"];
    126     [webViewCreate stringByEvaluatingJavaScript:@"document.execCommand('SelectAll')"];
    127     __block bool finished = NO;
    128     [delegate setStoreAppHighlightCallback:^(WKWebView *delegateWebView, _WKAppHighlight *highlight, BOOL inNewGroup, BOOL requestOriginatedInApp) {
    129         EXPECT_EQ(delegateWebView, webViewCreate.get());
    130         EXPECT_NOT_NULL(highlight);
    131         EXPECT_WK_STREQ(highlight.text, @"Test");
    132         EXPECT_NOT_NULL(highlight.highlight);
    133        
    134         [webViewRestore synchronouslyLoadHTMLString:@"Not the same"];
    135         [webViewRestore _restoreAppHighlights:@[ highlight.highlight ]];
    136        
    137         TestWebKitAPI::Util::waitForConditionWithLogging([&] () -> bool {
    138             return ![webViewRestore stringByEvaluatingJavaScript:@"internals.numberOfAppHighlights()"].intValue;
    139         }, 2, @"Expected Highlights to be populated.");
    140        
    141         finished = YES;
    142     }];
    143     [webViewCreate _addAppHighlight];
    144     TestWebKitAPI::Util::run(&finished);
     209
     210    [webViewRestore synchronouslyLoadHTMLString:@"Test"];
     211    [webViewRestore _restoreAppHighlights:@[ storedData ]];
     212   
     213    TestWebKitAPI::Util::waitForConditionWithLogging([&] () -> bool {
     214        return [webViewRestore stringByEvaluatingJavaScript:@"internals.numberOfAppHighlights()"].intValue == 1;
     215    }, 2, @"Expected Highlights to be populated.");
    145216}
    146217
Note: See TracChangeset for help on using the changeset viewer.