tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

TestOfflineClockDriver.cpp (1956B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "MockGraphInterface.h"
      8 #include "gtest/gtest.h"
      9 #include "mozilla/gtest/WaitFor.h"
     10 
     11 using namespace mozilla;
     12 using testing::InSequence;
     13 using testing::Return;
     14 
     15 TEST(TestOfflineClockDriver, TimeAdvance)
     16 MOZ_CAN_RUN_SCRIPT_BOUNDARY {
     17  TrackRate rate =
     18      CubebUtils::PreferredSampleRate(/* aShouldResistFingerprinting */ false);
     19  RefPtr graph = new MockGraphInterface(rate);
     20  RefPtr driver = new OfflineClockDriver(graph, rate);
     21  MozPromiseHolder<GenericPromise> doneHolder;
     22  RefPtr<GenericPromise> done = doneHolder.Ensure(__func__);
     23  {
     24    GraphTime length = WEBAUDIO_BLOCK_SIZE / 4;  // < WEBAUDIO_BLOCK_SIZE
     25    auto EnsureNextIteration = [&](GraphTime aTime) {
     26      driver->EnsureNextIteration();
     27    };
     28    InSequence s;
     29    EXPECT_CALL(*graph, MockIteration(0))
     30        // Time should not advance on the first iteration to process control
     31        // messages
     32        .WillOnce(EnsureNextIteration)
     33        // ... nor on subsequent.
     34        .WillOnce([&driver, length](GraphTime aTime) {
     35          driver->SetTickCountToRender(length);
     36          driver->EnsureNextIteration();
     37        });
     38    EXPECT_CALL(*graph, MockIteration(WEBAUDIO_BLOCK_SIZE))
     39        // Rendering iteration
     40        .WillOnce(EnsureNextIteration)
     41        // Time should not advance after rendering.
     42        .WillOnce([&](GraphTime aTime) {
     43          // Tell the driver to exit its event loop.
     44          graph->StopIterating();
     45          doneHolder.Resolve(true, __func__);
     46        });
     47  }
     48 
     49  graph->SetCurrentDriver(driver);
     50  driver->EnsureNextIteration();
     51  driver->Start();
     52  WaitForResolve(done);
     53  // Clean up.
     54  driver->Shutdown();
     55 }