~mhr3/libunity/fix-937464

« back to all changes in this revision

Viewing changes to test/vala/test-lens.vala

  • Committer: Tarmac
  • Author(s): Pawel Stolowski
  • Date: 2012-08-15 14:57:02 UTC
  • mfrom: (153.3.18 libunity.preview-close)
  • Revision ID: tarmac-20120815145702-nxzalmabsj0z7i7i
Implemented 'close' signal for previews.. Fixes: . Approved by Michal Hruby.

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
    Test.add_data_func ("/Unit/Lens/Activation", test_lens_activation);
57
57
    Test.add_data_func ("/Unit/Lens/Preview", test_lens_preview);
58
58
    Test.add_data_func ("/Unit/Lens/PreviewSignal", test_lens_preview_signal);
 
59
    Test.add_data_func ("/Unit/Lens/PreviewClosedSignal", test_lens_preview_closed_signal);
59
60
 
60
61
    Test.run ();
61
62
 
912
913
    assert (request_item_signal_count == 0);
913
914
  }
914
915
 
 
916
  public static void test_lens_preview_closed_signal ()
 
917
  {
 
918
    SignalWrapper[] signals = null;
 
919
    assert (local_scope != null);
 
920
 
 
921
    var ml = new MainLoop ();
 
922
 
 
923
    bool got_preview_uri_signal = false;
 
924
    int got_closed_signal = 0;
 
925
 
 
926
    var preview = new Unity.GenericPreview ("title", "description", null);
 
927
 
 
928
    // this signal handler gets called when we updates are sent in the last step of the test
 
929
    signals += new SignalWrapper (preview,
 
930
      preview.closed.connect (() =>
 
931
    {
 
932
      got_closed_signal++;
 
933
    }));
 
934
 
 
935
    // this signal handler gets called when activate is called with PREVIEW_RESULT
 
936
    signals += new SignalWrapper (local_scope,
 
937
      local_scope.preview_uri.connect ((uri) =>
 
938
    {
 
939
      assert (uri == "scheme://local/");
 
940
      got_preview_uri_signal = true;
 
941
      return preview;
 
942
    }));
 
943
 
 
944
    ml = new MainLoop ();
 
945
 
 
946
    var lens_results_model =
 
947
      exported_lens.get_model_internal (0) as Dee.SharedModel;
 
948
    var iter = lens_results_model.get_first_iter ();
 
949
    var mangled_uri = lens_results_model.get_string (iter, 0);
 
950
 
 
951
    Unity.Protocol.GenericPreview? reconstructed = null;
 
952
    call_lens_activate (mangled_uri, Unity.Protocol.ActionType.PREVIEW_RESULT, (reply) =>
 
953
    {
 
954
      var v = reply.get_child_value (0);
 
955
      Unity.Protocol.ActivationReplyRaw reply_struct =
 
956
        (Unity.Protocol.ActivationReplyRaw) v;
 
957
      reconstructed = (Unity.Protocol.GenericPreview?)Unity.Protocol.Preview.parse (reply_struct.hints["preview"]);
 
958
      ml.quit ();
 
959
    });
 
960
    run_with_timeout (ml, 5000);
 
961
 
 
962
    assert (reconstructed != null);
 
963
    assert (got_closed_signal == 0);
 
964
 
 
965
    // send preview_closed "signal"; this will result in setting action=close in the updates hashtable.
 
966
    reconstructed.begin_updates();
 
967
    reconstructed.preview_closed();
 
968
    var updates = reconstructed.end_updates_as_hashtable();
 
969
 
 
970
    assert (updates != null);
 
971
    assert (updates.size() == 1);
 
972
    assert (updates.contains("base-preview-action"));
 
973
    assert (updates["base-preview-action"].get_string() == "closed");
 
974
 
 
975
    ml = new MainLoop ();
 
976
 
 
977
    // send 'closed' signal
 
978
    call_lens_update_preview_property (mangled_uri, updates, (reply) =>
 
979
    {
 
980
      ml.quit ();
 
981
    });
 
982
    run_with_timeout (ml, 5000);
 
983
 
 
984
    assert (got_closed_signal == 1);
 
985
  }
915
986
}